wvmoreira / jquery-numberformatter

Automatically exported from code.google.com/p/jquery-numberformatter
0 stars 0 forks source link

Rounding error of negative numbers. #64

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. load the numberformatter
2. run (-0.5).toFixed(0);

What is the expected output? What do you see instead?
The expected output is -1. Instead I see 0.

What version of the product are you using? On what operating system?
I was using numberformatter 1.2.2 and now 1.2.3. On Windows 7 64bit, and MacOS 
X. All on firefox, Opera and Chrome. Newest version.

Please provide any additional information below.

Original issue reported on code.google.com by rico.sas...@gmail.com on 16 May 2012 at 11:45

GoogleCodeExporter commented 8 years ago
I analyzed the function and I found out that Math.round() is responsible for 
that bug. Math.round(-0.5) returns 0.

Original comment by rico.sas...@gmail.com on 7 Jun 2012 at 12:38

GoogleCodeExporter commented 8 years ago
There are several rounding schemes possible, this is just the default 
javascript one. Rounding -0.5 to -1 is not strictly correct, if Math.round 
rounds it to 0 then that is the rounding mode supported.

Format number assumes you have parsed the number already, so you can do your 
own rounding before formatting it anyway.

No plans to support multiple rounding modes right now inside the code.

Original comment by apar...@gmail.com on 18 Oct 2013 at 12:41