1// Copyright JS Foundation and other contributors, http://js.foundation 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15//This test will not pass on FLOAT32 due to precision issues 16 17assert((123.56).toFixed() === "124"); 18assert((123.56).toFixed(0) === "124"); 19assert((123.56).toFixed(1) === "123.6"); 20assert((123.56).toFixed(5) === "123.56000"); 21assert((1.23e-10).toFixed(2) === "0.00"); 22assert((1.23e+20).toFixed(2) === "123000000000000000000.00"); 23assert((1.23e+21).toFixed(2) === "1.23e+21"); 24assert((-1.23).toFixed(1) === "-1.2"); 25assert((0.00023).toFixed(0) === "0"); 26assert((0.356).toFixed(2) === "0.36"); 27assert((0.0000356).toFixed(5) === "0.00004"); 28assert((0.000030056).toFixed(7) === "0.0000301"); 29assert(Infinity.toFixed(0) === "Infinity"); 30assert((-Infinity).toFixed(0) === "-Infinity"); 31assert(NaN.toFixed(0) === "NaN"); 32assert((0.0).toFixed(0) === "0"); 33assert((0.0).toFixed(1) === "0.0"); 34assert((-0.0).toFixed(0) === "0"); 35assert((-0.0).toFixed(1) === "0.0"); 36assert((123456789012345678901.0).toFixed(20) === "123456789012345683968.00000000000000000000"); 37assert((123.56).toFixed(NaN) === "124"); 38assert((123.56).toFixed(-0.9) === "124"); 39assert((0.095).toFixed(2) === "0.10"); 40assert((0.995).toFixed(2) === "0.99"); 41assert((9.995).toFixed(2) === "9.99"); 42assert((7.995).toFixed(2) === "8.00"); 43assert((8.995).toFixed(2) === "8.99"); 44assert((99.995).toFixed(2) === "100.00"); 45 46try { 47 Number.prototype.toExponential.call(new Object()); 48 assert(false); 49} catch (e) { 50 assert(e instanceof TypeError) 51} 52 53try { 54 (12).toFixed(-1); 55 assert(false); 56} catch (e) { 57 assert(e instanceof RangeError) 58} 59 60try { 61 (12).toFixed(21); 62 assert(false); 63} catch (e) { 64 assert(e instanceof RangeError) 65} 66 67assert ((0.5).toFixed(0) === "1"); 68assert ((1.5).toFixed(0) === "2"); 69assert ((12.5).toFixed(0) === "13"); 70assert ((123.5).toFixed(0) === "124"); 71assert ((1234.5).toFixed(0) === "1235"); 72assert ((0.567).toFixed(0) === "1"); 73assert ((1.567).toFixed(0) === "2"); 74assert ((12.567).toFixed(0) === "13"); 75assert ((123.567).toFixed(0) === "124"); 76assert ((1234.567).toFixed(0) === "1235"); 77 78assert ((1.2567).toFixed(0) === "1"); 79assert ((1.2567).toFixed(1) === "1.3"); 80assert ((1.2567).toFixed(2) === "1.26"); 81assert ((1.2567).toFixed(3) === "1.257"); 82assert ((1.2567).toFixed(4) === "1.2567"); 83assert ((1.2567).toFixed(5) === "1.25670"); 84 85assert ((12.3567).toFixed(0) === "12"); 86assert ((12.3567).toFixed(1) === "12.4"); 87assert ((12.3567).toFixed(2) === "12.36"); 88assert ((12.3567).toFixed(3) === "12.357"); 89assert ((12.3567).toFixed(4) === "12.3567"); 90assert ((12.3567).toFixed(5) === "12.35670"); 91 92assert ((123.4567).toFixed(0) === "123"); 93assert ((123.4567).toFixed(1) === "123.5"); 94assert ((123.4567).toFixed(2) === "123.46"); 95assert ((123.4567).toFixed(3) === "123.457"); 96assert ((123.4567).toFixed(4) === "123.4567"); 97assert ((123.4567).toFixed(5) === "123.45670"); 98