1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325
|
shouldBe("Number()", "0");
shouldBe("Number(1)", "1");
shouldBe("Number(1.1)", "1.1");
shouldBe("Number('1.2')", "1.2");
shouldBe("Number(true)", "1");
shouldBe("Number(false)", "0");
shouldBe("Number(null)", "0");
shouldBe("isNaN(Number(undefined))", "true");
shouldBe("isNaN(Number('a'))", "true");
shouldBe("isNaN(Number({}))", "true");
shouldBe("typeof Number(1)", "'number'");
shouldBe("Number({ valueOf: function() { return 33; } })", "33");
shouldBe("Number({ toString: function() { return 44; } })", "44");
shouldBe("Number({ valueOf: function() { return 33; }, toString: function() { return 44; }})", "33");
shouldThrow("Number({ valueOf: function() { throw 33; } })");
shouldBe("(new Number()).valueOf()", "0");
shouldBe("(new Number(.4)).valueOf()", "0.4");
shouldBe("(new Number('1.')).valueOf()", "1");
shouldBe("(new Number(true)).valueOf()", "1");
shouldBe("(new Number(false)).valueOf()", "0");
shouldBe("(new Number(null)).valueOf()", "0");
shouldBe("isNaN(new Number(undefined))", "true");
shouldBe("isNaN(new Number('a'))", "true");
shouldBe("isNaN(Number({}))", "true");
shouldBe("typeof new Number(1)", "'object'");
shouldBe("isNaN(Number.NaN)", "true");
shouldBe("Number.NEGATIVE_INFINITY", "-Infinity");
shouldBe("Number.POSITIVE_INFINITY", "Infinity");
// with (Number)
// shouldBe("POSITIVE_INFINITY", "Infinity");
shouldBe("(1).toString()", "'1'");
shouldBe("typeof (1).toString()", "'string'");
shouldBe("(10).toString(16)", "'a'");
shouldBe("(8.5).toString(16)", "'8.8'");
shouldBe("(-8.5).toString(16)", "'-8.8'");
shouldBe("Number.NaN.toString(16)", "'NaN'");
shouldBe("Number.POSITIVE_INFINITY.toString(16)", "'Infinity'");
shouldBe("Number.NEGATIVE_INFINITY.toString(16)", "'-Infinity'");
shouldBe("Number.MAX_VALUE.toString(2).length", "1024");
shouldBe("(1).valueOf()", "1");
shouldBe("typeof (1).valueOf()", "'number'");
function toFixedOrException(val,fractionDigits)
{
var s = "";
try {
s = String(Number(val).toFixed(fractionDigits));
}
catch (e) {
s = String(e);
}
return s;
}
shouldBe("Number(1234.567).toFixed(0)","\"1235\"");
shouldBe("Number(1234.567).toFixed(undefined)","\"1235\"");
shouldBe("Number(0).toFixed(7)","\"0.0000000\"");
shouldBe("Number(0.003).toFixed(0)","\"0\"");
shouldBe("Number(40.1234567890123).toFixed(7)","\"40.1234568\"");
shouldBe("Number(-40.1234567890123).toFixed(7)","\"-40.1234568\"");
shouldBe("Number(4).toFixed(7)","\"4.0000000\"");
shouldBe("Number(0.000056).toFixed(7)","\"0.0000560\"");
shouldBe("Number(NaN).toFixed(7)","\"NaN\"");
shouldBe("Number(Infinity).toFixed(7)","\"Infinity\"");
shouldBe("Number(-Infinity).toFixed(7)","\"-Infinity\"");
shouldBe("Number(Math.pow(10,4)).toFixed(13)","\"10000.0000000000000\"");
shouldBe("Number(Math.pow(10,17)).toFixed(16)","\"100000000000000000.0000000000000000\"");
shouldBe("Number(Math.pow(10,18)).toFixed(17)","\"1000000000000000000.00000000000000000\"");
shouldBe("Number(Math.pow(10,19)).toFixed(18)","\"10000000000000000000.000000000000000000\"");
shouldBe("Number(Math.pow(10,17)).toFixed(20)","\"100000000000000000.00000000000000000000\"");
shouldBe("Number(Math.pow(10,18)).toFixed(20)","\"1000000000000000000.00000000000000000000\"");
shouldBe("Number(Math.pow(10,19)).toFixed(20)","\"10000000000000000000.00000000000000000000\"");
shouldBe("Number(Math.pow(10,20)).toFixed(20)","\"100000000000000000000.00000000000000000000\"");
shouldBe("Number(Math.pow(10,21)).toFixed(20)","\"1e+21\"");
shouldBeTrue("toFixedOrException(2,-1).indexOf('Range') >= 0");
shouldBe("toFixedOrException(2,0)","\"2\"");
shouldBe("toFixedOrException(2,20)","\"2.00000000000000000000\"");
shouldBeTrue("toFixedOrException(2,21).indexOf('Range') >= 0");
shouldBe("Number(NaN).toExponential()","\"NaN\"");
shouldBe("Number(Infinity).toExponential()","\"Infinity\"");
shouldBe("Number(-Infinity).toExponential()","\"-Infinity\"");
shouldBe("Number(NaN).toExponential(4)","\"NaN\"");
shouldBe("Number(Infinity).toExponential(4)","\"Infinity\"");
shouldBe("Number(-Infinity).toExponential(4)","\"-Infinity\"");
shouldBe("Number(123.456).toExponential()","\"1.23456e+2\"");
shouldBeTrue("try { Number(123.456).toExponential(-1) } catch (e) { String(e).indexOf('Range') >= 0; }");
shouldBe("Number(123.456).toExponential(0)","\"1e+2\"");
shouldBe("Number(123.456).toExponential(1)","\"1.2e+2\"");
shouldBe("Number(123.456).toExponential(2)","\"1.23e+2\"");
shouldBe("Number(123.456).toExponential(3)","\"1.235e+2\"");
shouldBe("Number(123.456).toExponential(4)","\"1.2346e+2\"");
shouldBe("Number(123.456).toExponential(5)","\"1.23456e+2\"");
shouldBe("Number(123.456).toExponential(6)","\"1.234560e+2\"");
shouldBe("Number(123.456).toExponential(7)","\"1.2345600e+2\"");
shouldBe("Number(123.456).toExponential(8)","\"1.23456000e+2\"");
shouldBe("Number(123.456).toExponential(9)","\"1.234560000e+2\"");
shouldBe("Number(123.456).toExponential(10)","\"1.2345600000e+2\"");
shouldBe("Number(123.456).toExponential(11)","\"1.23456000000e+2\"");
shouldBe("Number(123.456).toExponential(12)","\"1.234560000000e+2\"");
shouldBe("Number(123.456).toExponential(13)","\"1.2345600000000e+2\"");
shouldBe("Number(123.456).toExponential(14)","\"1.23456000000000e+2\"");
shouldBe("Number(123.456).toExponential(15)","\"1.234560000000000e+2\"");
shouldBe("Number(123.456).toExponential(16)","\"1.2345600000000000e+2\"");
shouldBe("Number(123.456).toExponential(17)","\"1.23456000000000000e+2\"");
shouldBe("Number(123.456).toExponential(18)","\"1.234560000000000000e+2\"");
shouldBe("Number(123.456).toExponential(19)","\"1.2345600000000000000e+2\"");
shouldBe("Number(123.456).toExponential(20)","\"1.23456000000000000000e+2\"");
shouldBeTrue("try { Number(123.456).toExponential(21) } catch (e) { String(e).indexOf('Range') >= 0; }");
shouldBe("Number(.000123456).toExponential()","\"1.23456e-4\"");
shouldBeTrue("try { Number(.000123456).toExponential(-1) } catch (e) { String(e).indexOf('Range') >= 0; }");
shouldBe("Number(.000123456).toExponential(0)","\"1e-4\"");
shouldBe("Number(.000123456).toExponential(1)","\"1.2e-4\"");
shouldBe("Number(.000123456).toExponential(2)","\"1.23e-4\"");
shouldBe("Number(.000123456).toExponential(3)","\"1.235e-4\"");
shouldBe("Number(.000123456).toExponential(4)","\"1.2346e-4\"");
shouldBe("Number(.000123456).toExponential(5)","\"1.23456e-4\"");
shouldBe("Number(.000123456).toExponential(6)","\"1.234560e-4\"");
shouldBe("Number(.000123456).toExponential(7)","\"1.2345600e-4\"");
shouldBe("Number(.000123456).toExponential(8)","\"1.23456000e-4\"");
shouldBe("Number(.000123456).toExponential(9)","\"1.234560000e-4\"");
shouldBe("Number(.000123456).toExponential(10)","\"1.2345600000e-4\"");
shouldBe("Number(.000123456).toExponential(11)","\"1.23456000000e-4\"");
shouldBe("Number(.000123456).toExponential(12)","\"1.234560000000e-4\"");
shouldBe("Number(.000123456).toExponential(13)","\"1.2345600000000e-4\"");
shouldBe("Number(.000123456).toExponential(14)","\"1.23456000000000e-4\"");
shouldBe("Number(.000123456).toExponential(15)","\"1.234560000000000e-4\"");
shouldBe("Number(.000123456).toExponential(16)","\"1.2345600000000000e-4\"");
shouldBe("Number(.000123456).toExponential(17)","\"1.23456000000000000e-4\"");
shouldBe("Number(.000123456).toExponential(18)","\"1.234560000000000000e-4\"");
shouldBe("Number(.000123456).toExponential(19)","\"1.2345600000000000000e-4\"");
shouldBe("Number(.000123456).toExponential(20)","\"1.23456000000000000000e-4\"");
shouldBeTrue("try { Number(.000123456).toExponential(21) } catch (e) { String(e).indexOf('Range') >= 0; }");
shouldBe("Number(123.4567890123456789012).toExponential()","\"1.2345678901234568e+2\"");
shouldBeTrue("try { Number(123.4567890123456789012).toExponential(-1) } catch (e) { String(e).indexOf('Range') >= 0; }");
shouldBe("Number(123.4567890123456789012).toExponential(0)","\"1e+2\"");
shouldBe("Number(123.4567890123456789012).toExponential(1)","\"1.2e+2\"");
shouldBe("Number(123.4567890123456789012).toExponential(2)","\"1.23e+2\"");
shouldBe("Number(123.4567890123456789012).toExponential(3)","\"1.235e+2\"");
shouldBe("Number(123.4567890123456789012).toExponential(4)","\"1.2346e+2\"");
shouldBe("Number(123.4567890123456789012).toExponential(5)","\"1.23457e+2\"");
shouldBe("Number(123.4567890123456789012).toExponential(6)","\"1.234568e+2\"");
shouldBe("Number(123.4567890123456789012).toExponential(7)","\"1.2345679e+2\"");
shouldBe("Number(123.4567890123456789012).toExponential(8)","\"1.23456789e+2\"");
shouldBe("Number(123.4567890123456789012).toExponential(9)","\"1.234567890e+2\"");
shouldBe("Number(123.4567890123456789012).toExponential(10)","\"1.2345678901e+2\"");
shouldBe("Number(123.4567890123456789012).toExponential(11)","\"1.23456789012e+2\"");
shouldBe("Number(123.4567890123456789012).toExponential(12)","\"1.234567890123e+2\"");
shouldBe("Number(123.4567890123456789012).toExponential(13)","\"1.2345678901235e+2\"");
shouldBe("Number(123.4567890123456789012).toExponential(14)","\"1.23456789012346e+2\"");
shouldBe("Number(123.4567890123456789012).toExponential(15)","\"1.234567890123457e+2\"");
shouldBe("Number(123.4567890123456789012).toExponential(16)","\"1.2345678901234570e+2\"");
shouldBe("Number(123.4567890123456789012).toExponential(17)","\"1.23456789012345700e+2\"");
shouldBe("Number(123.4567890123456789012).toExponential(18)","\"1.234567890123457100e+2\"");
shouldBe("Number(123.4567890123456789012).toExponential(19)","\"1.2345678901234570000e+2\"");
shouldBe("Number(123.4567890123456789012).toExponential(20)","\"1.23456789012345700000e+2\"");
shouldBeTrue("try { Number(123.4567890123456789012).toExponential(21) } catch (e) { String(e).indexOf('Range') >= 0; }");
shouldBe("Number(.0000000000000000000001).toExponential()","\"1e-22\"");
shouldBe("Number(.0000000000000000000012).toExponential()","\"1.2e-21\"");
shouldBe("Number(.0000000000000000000123).toExponential()","\"1.23e-20\"");
shouldBe("Number(.0000000000000000000123).toExponential()","\"1.23e-20\"");
shouldBe("Number(.0000000000000000001234).toExponential()","\"1.234e-19\"");
shouldBe("Number(.0000000000000000012345).toExponential()","\"1.2345e-18\"");
shouldBe("Number(.0000000000000000123456).toExponential()","\"1.23456e-17\"");
shouldBe("Number(.0000000000000001234567).toExponential()","\"1.234567e-16\"");
shouldBe("Number(.0000000000000012345678).toExponential()","\"1.2345678e-15\"");
shouldBe("Number(.0000000000000123456789).toExponential()","\"1.23456789e-14\"");
shouldBe("Number(.0000000000001234567890).toExponential()","\"1.23456789e-13\"");
shouldBe("Number(.0000000000012345678901).toExponential()","\"1.2345678901e-12\"");
shouldBe("Number(.0000000000123456789012).toExponential()","\"1.23456789012e-11\"");
shouldBe("Number(.0000000001234567890123).toExponential()","\"1.234567890123e-10\"");
shouldBe("Number(.0000000012345678901234).toExponential()","\"1.2345678901234e-9\"");
shouldBe("Number(.0000000123456789012345).toExponential()","\"1.23456789012345e-8\"");
shouldBe("Number(.0000001234567890123456).toExponential()","\"1.234567890123456e-7\"");
shouldBe("Number(.0000012345678901234567).toExponential()","\"1.2345678901234567e-6\"");
shouldBe("Number(.0000123456789012345678).toExponential()","\"1.2345678901234568e-5\"");
shouldBe("Number(.0001234567890123456789).toExponential()","\"1.2345678901234567e-4\"");
shouldBe("Number(.0012345678901234567890).toExponential()","\"1.2345678901234567e-3\"");
shouldBe("Number(.0123456789012345678901).toExponential()","\"1.2345678901234568e-2\"");
shouldBe("Number(1.234567890123456789012).toExponential()","\"1.2345678901234567e+0\"");
shouldBe("Number(12.34567890123456789012).toExponential()","\"1.2345678901234567e+1\"");
shouldBe("Number(123.4567890123456789012).toExponential()","\"1.2345678901234568e+2\"");
shouldBe("Number(1234.567890123456789012).toExponential()","\"1.234567890123457e+3\"");
shouldBe("Number(12345.67890123456789012).toExponential()","\"1.2345678901234567e+4\"");
shouldBe("Number(123456.7890123456789012).toExponential()","\"1.2345678901234567e+5\"");
shouldBe("Number(1234567.890123456789012).toExponential()","\"1.2345678901234567e+6\"");
shouldBe("Number(12345678.90123456789012).toExponential()","\"1.2345678901234567e+7\"");
shouldBe("Number(123456789.0123456789012).toExponential()","\"1.2345678901234567e+8\"");
shouldBe("Number(1234567890.123456789012).toExponential()","\"1.2345678901234567e+9\"");
shouldBe("Number(12345678901.23456789012).toExponential()","\"1.2345678901234568e+10\"");
shouldBe("Number(123456789012.3456789012).toExponential()","\"1.2345678901234567e+11\"");
shouldBe("Number(1234567890123.456789012).toExponential()","\"1.2345678901234568e+12\"");
shouldBe("Number(12345678901234.56789012).toExponential()","\"1.2345678901234568e+13\"");
shouldBe("Number(123456789012345.6789012).toExponential()","\"1.2345678901234567e+14\"");
shouldBe("Number(1234567890123456.789012).toExponential()","\"1.2345678901234568e+15\"");
shouldBe("Number(12345678901234567.89012).toExponential()","\"1.2345678901234568e+16\"");
shouldBe("Number(123456789012345678.9012).toExponential()","\"1.2345678901234568e+17\"");
shouldBe("Number(1234567890123456789.012).toExponential()","\"1.2345678901234568e+18\"");
shouldBe("Number(12345678901234567890.12).toExponential()","\"1.2345678901234567e+19\"");
shouldBe("Number(123456789012345678901.2).toExponential()","\"1.2345678901234568e+20\"");
shouldBe("Number(-18450000000000000000).toExponential(6)", "\"-1.845000e+19\"");
shouldBeTrue("try { Number(1).toPrecision(-1); } catch (e) { String(e).indexOf('Range') >= 0; }");
shouldBeTrue("try { Number(1).toPrecision(0); } catch (e) { String(e).indexOf('Range') >= 0; }");
shouldBe("try { Number(1).toPrecision(1); } catch (e) { String(e); }","\"1\"");
shouldBe("try { Number(1).toPrecision(21); } catch (e) { String(e); }","\"1.00000000000000000000\"");
shouldBeTrue("try { Number(1).toPrecision(22); } catch (e) { String(e).indexOf('Range') >= 0; }");
shouldBe("Number(NaN).toPrecision()","\"NaN\"");
shouldBe("Number(NaN).toPrecision(1)","\"NaN\"");
shouldBe("Number(Infinity).toPrecision()","\"Infinity\"");
shouldBe("Number(Infinity).toPrecision(1)","\"Infinity\"");
shouldBe("Number(-Infinity).toPrecision()","\"-Infinity\"");
shouldBe("Number(-Infinity).toPrecision(1)","\"-Infinity\"");
shouldBe("Number(.0000000012345).toPrecision(2)","\"1.2e-9\"");
shouldBe("Number(.000000012345).toPrecision(2)","\"1.2e-8\"");
shouldBe("Number(.00000012345).toPrecision(2)","\"1.2e-7\"");
shouldBe("Number(.0000012345).toPrecision(2)","\"0.0000012\"");
shouldBe("Number(.000012345).toPrecision(2)","\"0.000012\"");
shouldBe("Number(.00012345).toPrecision(2)","\"0.00012\"");
shouldBe("Number(.0012345).toPrecision(2)","\"0.0012\"");
shouldBe("Number(.012345).toPrecision(2)","\"0.012\"");
shouldBe("Number(.12345).toPrecision(2)","\"0.12\"");
shouldBe("Number(1.2345).toPrecision(2)","\"1.2\"");
shouldBe("Number(12.345).toPrecision(2)","\"12\"");
shouldBe("Number(123.45).toPrecision(2)","\"1.2e+2\"");
shouldBe("Number(1234.5).toPrecision(2)","\"1.2e+3\"");
shouldBe("Number(12345).toPrecision(2)","\"1.2e+4\"");
shouldBe("Number(12345.67).toPrecision(4)","\"1.235e+4\"");
shouldBe("Number(12344.67).toPrecision(4)","\"1.234e+4\"");
shouldBe("Number(0.0001234567890123456789012345).toPrecision()","\"0.00012345678901234567\"");
shouldBe("Number(0.0001234567890123456789012345).toPrecision(1)","\"0.0001\"");
shouldBe("Number(0.0001234567890123456789012345).toPrecision(2)","\"0.00012\"");
shouldBe("Number(0.0001234567890123456789012345).toPrecision(3)","\"0.000123\"");
shouldBe("Number(0.0001234567890123456789012345).toPrecision(4)","\"0.0001235\"");
shouldBe("Number(0.0001234567890123456789012345).toPrecision(5)","\"0.00012346\"");
shouldBe("Number(0.0001234567890123456789012345).toPrecision(6)","\"0.000123457\"");
shouldBe("Number(0.0001234567890123456789012345).toPrecision(7)","\"0.0001234568\"");
shouldBe("Number(0.0001234567890123456789012345).toPrecision(8)","\"0.00012345679\"");
shouldBe("Number(0.0001234567890123456789012345).toPrecision(9)","\"0.000123456789\"");
shouldBe("Number(0.0001234567890123456789012345).toPrecision(10)","\"0.0001234567890\"");
shouldBe("Number(0.0001234567890123456789012345).toPrecision(11)","\"0.00012345678901\"");
shouldBe("Number(0.0001234567890123456789012345).toPrecision(12)","\"0.000123456789012\"");
shouldBe("Number(0.0001234567890123456789012345).toPrecision(13)","\"0.0001234567890123\"");
shouldBe("Number(0.0001234567890123456789012345).toPrecision(14)","\"0.00012345678901235\"");
shouldBe("Number(0.0001234567890123456789012345).toPrecision(15)","\"0.000123456789012346\"");
shouldBe("Number(0.0001234567890123456789012345).toPrecision(16)","\"0.0001234567890123457\"");
shouldBe("Number(0.0001234567890123456789012345).toPrecision(17)","\"0.00012345678901234568\"");
shouldBe("Number(0.0001234567890123456789012345).toPrecision(18)","\"0.000123456789012345680\"");
shouldBe("Number(0.0001234567890123456789012345).toPrecision(19)","\"0.0001234567890123456800\"");
shouldBe("Number(0.0001234567890123456789012345).toPrecision(20)","\"0.00012345678901234567000\"");
shouldBe("Number(0.0001234567890123456789012345).toPrecision(21)","\"0.000123456789012345680000\"");
shouldBe("Number(12345.67890123456789012345).toPrecision()","\"12345.678901234567\"");
shouldBe("Number(12345.67890123456789012345).toPrecision(1)","\"1e+4\"");
shouldBe("Number(12345.67890123456789012345).toPrecision(2)","\"1.2e+4\"");
shouldBe("Number(12345.67890123456789012345).toPrecision(3)","\"1.23e+4\"");
shouldBe("Number(12345.67890123456789012345).toPrecision(4)","\"1.235e+4\"");
shouldBe("Number(12345.67890123456789012345).toPrecision(5)","\"12346\"");
shouldBe("Number(12345.67890123456789012345).toPrecision(6)","\"12345.7\"");
shouldBe("Number(12345.67890123456789012345).toPrecision(7)","\"12345.68\"");
shouldBe("Number(12345.67890123456789012345).toPrecision(8)","\"12345.679\"");
shouldBe("Number(12345.67890123456789012345).toPrecision(9)","\"12345.6789\"");
shouldBe("Number(12345.67890123456789012345).toPrecision(10)","\"12345.67890\"");
shouldBe("Number(12345.67890123456789012345).toPrecision(11)","\"12345.678901\"");
shouldBe("Number(12345.67890123456789012345).toPrecision(12)","\"12345.6789012\"");
shouldBe("Number(12345.67890123456789012345).toPrecision(13)","\"12345.67890123\"");
shouldBe("Number(12345.67890123456789012345).toPrecision(14)","\"12345.678901235\"");
shouldBe("Number(12345.67890123456789012345).toPrecision(15)","\"12345.6789012346\"");
shouldBe("Number(12345.67890123456789012345).toPrecision(16)","\"12345.67890123457\"");
shouldBe("Number(12345.67890123456789012345).toPrecision(17)","\"12345.678901234568\"");
shouldBe("Number(12345.67890123456789012345).toPrecision(18)","\"12345.6789012345660\"");
shouldBe("Number(12345.67890123456789012345).toPrecision(19)","\"12345.67890123456800\"");
shouldBe("Number(12345.67890123456789012345).toPrecision(20)","\"12345.678901234565000\"");
shouldBe("Number(12345.67890123456789012345).toPrecision(21)","\"12345.6789012345670000\"");
shouldBe("Number(0).toPrecision()","\"0\"");
shouldBe("Number(0).toPrecision(1)","\"0\"");
shouldBe("Number(0).toPrecision(2)","\"0.0\"");
shouldBe("Number(0).toPrecision(3)","\"0.00\"");
shouldBe("Number(0).toPrecision(4)","\"0.000\"");
shouldBe("Number(0).toPrecision(5)","\"0.0000\"");
shouldBe("Number(0).toPrecision(6)","\"0.00000\"");
shouldBe("Number(0).toPrecision(7)","\"0.000000\"");
shouldBe("Number(0).toPrecision(8)","\"0.0000000\"");
shouldBe("Number(0).toPrecision(9)","\"0.00000000\"");
shouldBe("Number(0).toPrecision(10)","\"0.000000000\"");
shouldBe("Number(0).toPrecision(11)","\"0.0000000000\"");
shouldBe("Number(0).toPrecision(12)","\"0.00000000000\"");
shouldBe("Number(0).toPrecision(13)","\"0.000000000000\"");
shouldBe("Number(0).toPrecision(14)","\"0.0000000000000\"");
shouldBe("Number(0).toPrecision(15)","\"0.00000000000000\"");
shouldBe("Number(0).toPrecision(16)","\"0.000000000000000\"");
shouldBe("Number(0).toPrecision(17)","\"0.0000000000000000\"");
shouldBe("Number(0).toPrecision(18)","\"0.00000000000000000\"");
shouldBe("Number(0).toPrecision(19)","\"0.000000000000000000\"");
shouldBe("Number(0).toPrecision(20)","\"0.0000000000000000000\"");
shouldBe("Number(0).toPrecision(21)","\"0.00000000000000000000\"");
// http://bugs.kde.org/136734
shouldBe("(1.0).toPrecision(6)", "'1.00000'");
shouldBe("(10.0).toPrecision(6)", "'10.0000'");
shouldBe("(0.1).toPrecision(6)", "'0.100000'");
shouldBe("(1.000000001).toPrecision(6)", "'1.00000'");
shouldBe("(-0.0).toPrecision(3)", "'0.00'");
shouldBe("(-0.0).toFixed()", "'0'");
shouldBe("(-0.0).toFixed(3)", "'0.000'");
shouldBe("(-0.00001).toFixed(3)", "'-0.000'");
shouldBe("Number.length", "1");
shouldBe("Number(Number.prototype)", "0");
shouldBeTrue("Number.prototype.constructor === Number");
shouldBeTrue("(new Number()).__proto__ == Number.prototype");
shouldBeTrue("Number().__proto__ == Number.prototype");
// 'this' object has to be a number
var f = Number.prototype.toFixed;
shouldBe("f.call(1, 2)", "'1.00'");
shouldBe("f.call(new Number(3), 2)", "'3.00'");
shouldThrow("f.call(undefined, 2)");
shouldThrow("f.call(null, 2)");
shouldThrow("f.call({}, 2)");
|