I am trying to add this large decimal number together to get 9999999999.9999999999 but instead I am getting 10000000000.
Here is the code:
function add(x, y) {
var filterFloat = function (value) {
if(/^(\-|\+)?([0-9]+(\.[0-9]+)?|Infinity)$/
.test(value))
return Number(value);
return NaN;
}
if (typeof x == 'string') {
filterFloat(x);
console.log(x);
};
if (typeof y == 'string') {
filterFloat(y);
console.log(y);
};
var z = filterFloat(x) + filterFloat(y);
//var short = z.toFixed(4);
//console.log(short);
//return short.toString();
//return z.toString();
return z;
var zz = z.toString();
return zz;
//console.log(typeof zz);
}
Here is the argument being passed:
add("1234567890.0987654321", "8765432109.9012345678");
See the fiddle below: