0

So on my site, I choose items. Prices example are:

0.24$, $0.16, $0.15, $0.03

If you put all together you get $0.58. Okay, great! Now, I am doing same on my JavaScript and then showing that number with "commas" so it looks nicer, but I am getting something like this: $0.5,800,000,000,000,001.. Why is that happening?

function numberWithCommas(x) {
    return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
Siguza
  • 15,723
  • 6
  • 44
  • 66

0 Answers0