Skip to content

Commit 54e036f

Browse files
author
Tom Groves
committed
fallback to native rounding if newer approach fails
1 parent b62b1b1 commit 54e036f

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

bits/60_number.js

+4
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ function rnd(val/*:number*/, d/*:number*/)/*:string*/ {
6363
}
6464
result = +(Math.round(+arr[0] + "e" + sig + (+arr[1] + d)) + "e-" + d);
6565
}
66+
if (isNaN(result)) {
67+
var dd = Math.pow(10, d);
68+
result = Math.round(val * dd) / dd;
69+
}
6670
return "" + result
6771
}
6872
function dec(val/*:number*/, d/*:number*/)/*:number*/ {

ssf.flow.js

+4
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,10 @@ function rnd(val/*:number*/, d/*:number*/)/*:string*/ {
324324
}
325325
result = +(Math.round(+arr[0] + "e" + sig + (+arr[1] + d)) + "e-" + d);
326326
}
327+
if (isNaN(result)) {
328+
var dd = Math.pow(10, d);
329+
result = Math.round(val * dd) / dd;
330+
}
327331
return "" + result
328332
}
329333
function dec(val/*:number*/, d/*:number*/)/*:number*/ {

ssf.js

+4
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,10 @@ function rnd(val, d) {
319319
}
320320
result = +(Math.round(+arr[0] + "e" + sig + (+arr[1] + d)) + "e-" + d);
321321
}
322+
if (isNaN(result)) {
323+
var dd = Math.pow(10, d);
324+
result = Math.round(val * dd) / dd;
325+
}
322326
return "" + result
323327
}
324328
function dec(val, d) {

0 commit comments

Comments
 (0)