Skip to content

Commit 2f20180

Browse files
committed
Merge pull request processing-js#37 from davidleibovic/fix-bug-1828
unit tests pass, code looks good.
2 parents 09ce6ae + 7e71e38 commit 2f20180

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
@@ -9073,7 +9073,7 @@
90739073
* @see nfs
90749074
* @see nfp
90759075
*/
9076-
p.nfc = function(value, leftDigits, rightDigits) { return nfCore(value, "", "-", leftDigits, rightDigits, ","); };
9076+
p.nfc = function(value, rightDigits) { return nfCore(value, "", "-", 0, rightDigits, ","); };
90779077

90789078
var decimalToHex = function(d, padding) {
90799079
//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)