Amount should be 2 decimal places only, no commas or dollar sign in JS

I need help with this, I have been trying I cannot make it work :

Numeric - Decimal Places. Amount should be 2 decimal places only, no commas or dollar sign. So a check totaling $450,000.00 should appear as 450000.00

1 answer

  • answered 2018-10-11 19:21 not a number

    You can use Number.prototype.toFixed()

    Examples:

    let sum = 450000;
    console.log(sum.toFixed(2));
    
    let sum2 = 123.456;
    console.log(sum2.toFixed(2));
    
    let sum3 = 1234.56789;
    console.log(sum3.toFixed(3));