I have the following javascript code which does a sum of strings converted to floats:
$(document).on("change", ".changeValue", function (e) {
$(this).closest(".mdl-textfield--floating-label").find(".emptyRateError").css("display", "flex").css("visibility", "hidden");
var elemClass = $(this).Get_Attr_Regex('optionValue_', 'class');
var elemSum = $(".optionSum_" + elemClass.substring(elemClass.indexOf("_")+1, elemClass.length));
var sum = 0;
$("." + elemClass).each(function (index) {
sum += parseFloat($(this).val());
});
elemSum.val(sum);
});
However, at times, when I have values "1.2" and "4.4", the value returned as sum is 5.6000000000000005.
Any idea why I am getting this behaviour? Thanks