sansanbgl / jquery-formatcurrency

Automatically exported from code.google.com/p/jquery-formatcurrency
GNU General Public License v3.0
0 stars 0 forks source link

isPositive check #12

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Put any negative number between 0 and -1 for example -0.25 in a textbox.
2. Apply the formatCurrency with standard options. 

What is the expected output? What do you see instead?
(0.25) according to the default negative number representation, but the 
result is 0.25. The number seems to be considered as positive.

I think this is because of this check

// format number
var numParts = String(num).split('.');
num = numParts[0];
var isPositive = (num == (num = Math.abs(num)));

0 is an unsigned number so it will result all the time as positive number, 
but -0.25 is not positive.

Sorry for the noob question but... why you don't check simply for

num < 0

What version of the product are you using? On what operating system?

formatcurrency 1.1.0 in windows XP SP3. But I don't think it's an issue 
related to the OS

Regards.

Original issue reported on code.google.com by morpheus...@gmail.com on 24 Nov 2009 at 9:00

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Actually I made some changes to the original source code to better fit the 
expected 
behavior; these are the change I have done, from:

// format number
var numParts = String(num).split('.');
num = numParts[0];
var isPositive = (num == (num = Math.abs(num)));

To:

// format number
var numParts = String(num).split('.');
var isPositive = (num >= 0);
num = Math.abs(numParts[0]);

Well probably is not the better and cleaner way... but seems to work perfectly, 
at
least for me.

Original comment by morpheus...@gmail.com on 25 Nov 2009 at 9:54

GoogleCodeExporter commented 8 years ago
Fixed in trunk

Original comment by bdewe...@hotmail.com on 28 Nov 2009 at 2:48

GoogleCodeExporter commented 8 years ago

Original comment by bdewe...@hotmail.com on 28 Nov 2009 at 3:11

GoogleCodeExporter commented 8 years ago

Original comment by bdewe...@hotmail.com on 28 Nov 2009 at 3:12