adamwdraper / Numeral-js

A javascript library for formatting and manipulating numbers.
http://numeraljs.com
MIT License
9.66k stars 927 forks source link

Formatting a negative currency with rounding results in an invalid string #777

Open Vesuri opened 2 years ago

Vesuri commented 2 years ago

When using the format string "$0,0.00" formatting a value in the range -0.005 <= value < 0 results in the string 0$.00 instead of $0.00:

>> numeral(5).format("$0,0.00");
"$5.00"
>> numeral(0.05).format("$0,0.00");
"$0.05"
>> numeral(0.005).format("$0,0.00");
"$0.01"
>> numeral(0.004).format("$0,0.00");
"$0.00"
>> numeral(-0.000).format("$0,0.00");
"$0.00"
>> numeral(-0.001).format("$0,0.00");
"0$.00"
>> numeral(-0.005).format("$0,0.00");
"0$.00"
>> numeral(-0.006).format("$0,0.00");
"-$0.01"

Numeral version 2.0.6. Tested with Firefox version 105.0.1 and Chrome version 105.0.5195.125.

fredrivett commented 1 year ago

I'm also seeing the strange behaviour (also on numeral 2.0.6):

>> numeral(-0.005).format("$0,0.00");
"0$.00"

EDIT: FWIW it seems numbro (a more recently maintained fork of this repo) doesn't have this issue for me.

zahidmak24 commented 10 months ago

Is there a plan to address this issue?