X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=tests%2Fnumber-format.html;h=f722ff25e6d79717571eae4fe06112233898a24c;hb=c0e7b6254d879d6ccbfdd97b88eb904cc09cc9c1;hp=e17a15c41208031bf61aa4ad6e8af2fbb97d17bd;hpb=15b00ba8914e0da9ad5dca2917d7743004485e73;p=dygraphs.git diff --git a/tests/number-format.html b/tests/number-format.html index e17a15c..f722ff2 100644 --- a/tests/number-format.html +++ b/tests/number-format.html @@ -1,16 +1,13 @@ + + Test of number formatting - - - - - + + -

The default formatting mimicks printf with %.pg where p is +

The default formatting mimics printf with %.pg where p is the precision to use. It turns out that JavaScript's toPrecision() method is almost but not exactly equal to %g; they differ for values with small absolute values (10^-1 to 10^-5 or so), with toPrecision() @@ -58,21 +55,21 @@ }; updateTable = function() { - var headers = ['Dygraph.defaultFormat()', 'toPrecision()', - 'Dygraph.defaultFormat()', 'toPrecision()']; + var headers = ['Dygraph.floatFormat()', 'toPrecision()', + 'Dygraph.floatFormat()', 'toPrecision()']; var numbers = []; var p = parseInt(document.getElementById('p_input').value); for (var i = -10; i <= 10; i++) { var n = Math.pow(10, i); - numbers.push([Dygraph.defaultFormat(n, p), + numbers.push([Dygraph.floatFormat(n, p), n.toPrecision(p), - Dygraph.defaultFormat(Math.PI * n, p), + Dygraph.floatFormat(Math.PI * n, p), (Math.PI * n).toPrecision(p)]); } // Check exact values of 0. - numbers.push([Dygraph.defaultFormat(0.0, p), + numbers.push([Dygraph.floatFormat(0.0, p), 0.0.toPrecision(p)]); var elem = document.getElementById('content');