From e9a745646a424498c58ae65cc24404d12b5a1f80 Mon Sep 17 00:00:00 2001 From: Daniel Ehrenberg Date: Thu, 23 Mar 2017 19:05:32 +0100 Subject: [PATCH] Test for the difference between toFixed and toString This test comes from a note in the specification under toFixed. It fails in ChakraCore and passes in other engines that I tested. --- .../Number/prototype/toFixed/exactness.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 test/built-ins/Number/prototype/toFixed/exactness.js diff --git a/test/built-ins/Number/prototype/toFixed/exactness.js b/test/built-ins/Number/prototype/toFixed/exactness.js new file mode 100644 index 0000000000..7626c665b3 --- /dev/null +++ b/test/built-ins/Number/prototype/toFixed/exactness.js @@ -0,0 +1,19 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-number.prototype.tofixed +description: Number.prototype.toFixed does not use ToString's cleaner rounding +info: > + Number.prototype.toFixed ( fractionDigits ) + + ... + 8. Else x < 10^21, + a. Let n be an integer for which the exact mathematical value of n รท 10f - x is as close to zero as possible. If there are two such n, pick the larger n. + b. If n = 0, let m be the String "0". Otherwise, let m be the String consisting of the digits of the decimal representation of n (in order, with no leading zeroes). + ... +---*/ + +// Test from a note in the specification +assert.sameValue((1000000000000000128).toString(0), "1000000000000000100"); +assert.sameValue((1000000000000000128).toFixed(0), "1000000000000000128");