var a = 1.1 + 1.2 + 1.3 + 1.1;
console.log(a); //4.699999999999999
var b = 1.1 + 1.2 + 1.3;
console.log(b); //3.5999999999999996
var c = 1.1 + 1.2 + 1.4;
console.log(c.toFixed(2));
var d = 1.1;
d+= 1.2;
d+=1.4;
console.log(d);
console.log(1.1+1.1+1.2); //3.4000000000000004
console.log(1.1+1.2+1.2); //3.5
console.log(1.1+1.1+1.1); //3.3000000000000003
function calculateWithPrecision() {
var maxDecimalLength = 0;
for (var i = 0; i < arguments.length; i++) {
var decimalLength = (arguments[i].toString().split('.')[1] || []).length;
if (decimalLength > maxDecimalLength) maxDecimalLength = decimalLength;
}
var sum = Array.prototype.reduce.call(arguments, function(a, b) { return a + b; }, 0);
return +sum.toFixed(maxDecimalLength);
}
console