Skip to content

Commit f0f4557

Browse files
committed
Fixed bug 1828 and added unit test
1 parent 7fd1a8e commit f0f4557

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

processing.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9071,7 +9071,7 @@
90719071
* @see nfs
90729072
* @see nfp
90739073
*/
9074-
p.nfc = function(value, leftDigits, rightDigits) { return nfCore(value, "", "-", leftDigits, rightDigits, ","); };
9074+
p.nfc = function(value, rightDigits) { return nfCore(value, "", "-", 0, rightDigits, ","); };
90759075

90769076
var decimalToHex = function(d, padding) {
90779077
//if there is no padding value added, default padding to 8 else go into while statement.

test/unit/nfc.pde

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
int a=200, b=-40000, c=1901024;
2+
3+
String sa = nfc(a);
4+
_checkEqual(sa, "200");
5+
6+
String sb = nfc(b);
7+
_checkEqual(sb, "-40,000");
8+
9+
String sc = nfc(c);
10+
_checkEqual(sc, "1,901,024");
11+
12+
float d = 200.94, e = 40000, f = -1901024.012;
13+
14+
String sd = nfc(d, 2);
15+
_checkEqual(sd, "200.94");
16+
17+
String se = nfc(e, 2);
18+
_checkEqual(se, "40,000.00");
19+
20+
String sf = nfc(f, 2);
21+
_checkEqual(sf, "-1,901,024.01");
22+
23+
// test to see if we can trim a long fractional number down to 2 decimal places
24+
_checkEqual(nfc(1000.56789, 2), "1,000.57");
25+
26+
// does rounding work correctly
27+
_checkEqual(nfc(-1234.99, 1), "-1,235.0");
28+
_checkEqual(nfc(-1234.994, 2), "-1,234.99");
29+

0 commit comments

Comments
 (0)