You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
programming-examples/js/Math/Format a number up to speci...

9 lines
328 B
JavaScript

function decimals(n, d) {
if ((typeof n !== 'number') || (typeof d !== 'number'))
return false;
n = parseFloat(n) || 0;
return n.toFixed(d);
}
console.log(decimals(2.100212, 2));
console.log(decimals(2.100212, 3));
console.log(decimals(2100, 2));