1 // Copyright (C) 2016 The V8 Project authors. All rights reserved.
2 // This code is governed by the BSD license found in the LICENSE file.
5 esid: sec-number.prototype.toprecision
7 Return a string containing the the number value of this if precision is
10 20.1.3 Properties of the Number Prototype Object
12 The Number prototype object is the intrinsic object %NumberPrototype%. The
13 Number prototype object is an ordinary object. The Number prototype is itself
14 a Number object; it has a [[NumberData]] internal slot with the value +0.
17 The abstract operation thisNumberValue(value) performs the following steps:
19 1. If Type(value) is Number, return value.
20 2. If Type(value) is Object and value has a [[NumberData]] internal slot, then
21 a. Assert: value's [[NumberData]] internal slot is a Number value.
22 b. Return the value of value's [[NumberData]] internal slot.
23 3. Throw a TypeError exception.
25 Number.prototype.toPrecision ( precision )
27 1. Let x be ? thisNumberValue(this value).
28 2. If precision is undefined, return ! ToString(x).
32 var n = new Number(7);
34 assert.sameValue(n.toPrecision(undefined), "7");
35 assert.sameValue((39).toPrecision(undefined), "39");
37 assert.sameValue(Number.prototype.toPrecision(), "0");
38 assert.sameValue((42).toPrecision(), "42");