0

I'm using AccountingJs to format currency, but not always the values that work are in the house of thousands. I also need to convert variables to hundreds, like $ 234.45

The problem is that this and other plugins and JS methods I've tried always convert the values into thousands, never into hundreds.

I am using the value 17652 as an example, but:

Accounting.formatMoney (17652); // returns 17,652 

Does anyone know of any way I can solve this?

Thanks!

Fernando Aureliano
  • 894
  • 12
  • 35
  • Why not divide by `100` before passing to your function? – BenM Jun 23 '17 at 20:02
  • @BenM I'd be uneasy about doing that. You can end up with strings like `84399.9999999999` when you do floating-point operations like this. For example, `0.06+0.01` gives `0.06999999999999999`. Having said that, I've failed to find an example of an `n` such that `n/100` is displayed wrongly in my browser (Firefox on Linux). – David Knipe Jun 23 '17 at 21:38
  • BenM: Its like David said. I tried, but I got the same result without cents... – Fernando Aureliano Jun 24 '17 at 01:18

1 Answers1

-1

According to the AccountingJS documentation, you'd need to supply the decimal place. http://openexchangerates.github.io/accounting.js/

Original Number:

123.5

will appear with AccountingJS:

123.50

Other than that you'll need to only supply 3 numbers to keep it in the hundreds. The amount of numbers you're supplying will always come out as thousands since you don't supply the decimal.

expenguin
  • 1,052
  • 2
  • 21
  • 42