0

I tried to format the Amount field to 2 digits using the Amount.toLocaleString() toLocaleString(undefined, { minimumFractionDigits: 2 }),

Screen Shot

Some of the Amount values are displayed correctly but few are incorrect like $52.85.00 should be displayed as $52.85

2 Answers2

0
function financial(x) {
    return Number.parseFloat(x).toFixed(2);
}

console.log(financial(123.456));

console.log(financial(0.004));`
0

You can use Number.prototype.toFixed() to format with a number of decimals. Note: The toFixed method will return a string, so you should convert back to an floating number if your goal is not just to display. For more info on .toFixed() method access document

let numberToBeFormatted = 212.121212;
let formattedNumber = parseFloat(numberToBeFormatted.toFixed(2))
Rohan Shenoy
  • 805
  • 10
  • 23