openexchangerates / accounting.js

A lightweight JavaScript library for number, money and currency formatting - fully localisable, zero dependencies.
http://openexchangerates.github.io/accounting.js
MIT License
4.95k stars 528 forks source link

Support negative zero (-0) when formatting money #108

Open ghost opened 9 years ago

ghost commented 9 years ago

The first problem was defaulting to zero (0) if the value was falsy in the unformat function:

number = value || 0;

If the number was -0 it was set to 0.

This default value for number was moved to after the check of being a number or not to prevent this from happening.


The second issue is determining negative numbers in JavaScript:

-0 < 0
false

So a new function isNegative was added to work with negative zeros as well.


Finally, a new test case was added that demonstrates that the new behavior works as intended.

ghost commented 9 years ago

Let me know if this needs any more work before it can be merged in and I'll be happy to make any changes. Thanks.