This translation is incomplete. Please help translate this article from English.

The toFixed() method formats a number using fixed-point notation.




ऐच्छिक. ये मापदंड दसम्लव के बाद आने वाले अंको की गिनती को दर्शाता है; ये संख्या ० से २० के बीच हो सकती है, जिसमे ० और २० भी स्वयं शामिल हैं. लेकिन परिपालन में इनसे बड़ी संख्या भी हो सकती है. अगर इस मापदंड को छोड़ दिया जाए तो इसकी संख्या अपने आप ० मानी जाती है.


एक स्ट्रिंग जो की दी गयी संख्या को फिक्स्ड पॉइंट नोटेशन के रूप में दर्शाता है.


 अगर digits बहुत छोटा या बहुत बड़ा है. ० से १०० का परिणाम RangeError नहीं होगा. Implementations are allowed to support larger and smaller values as chosen.
If this method is invoked on an object that is not a Number.


toFixed() returns a string representation of numObj that does not use exponential notation and has exactly digits digits after the decimal place. The number is rounded if necessary, and the fractional part is padded with zeros if necessary so that it has the specified length. If numObj is greater than 1e+21, this method simply calls Number.prototype.toString() and returns a string in exponential notation.

Javascript numbers do not represent all decimals precisely which can lead to unexpected results such as 0.1 + 0.2 === 0.3 returning false .


Using toFixed

var numObj = 12345.6789;

numObj.toFixed();       // Returns '12346': note rounding, no fractional part
numObj.toFixed(1);      // Returns '12345.7': note rounding
numObj.toFixed(6);      // Returns '12345.678900': note added zeros
(1.23e+20).toFixed(2);  // Returns '123000000000000000000.00'
(1.23e-10).toFixed(2);  // Returns '0.00'
2.34.toFixed(1);        // Returns '2.3'
2.35.toFixed(1);        // Returns '2.4'. Note it rounds up
2.55.toFixed(1);        // Returns '2.5'. Note it rounds down - see warning above
-2.34.toFixed(1);       // Returns -2.3 (due to operator precedence, negative number literals don't return a string...)
(-2.34).toFixed(1);     // Returns '-2.3' (...unless you use parentheses)


Specification Status Comment
ECMAScript 3rd Edition (ECMA-262) Standard Initial definition. Implemented in JavaScript 1.5.
ECMAScript 5.1 (ECMA-262)
The definition of 'Number.prototype.toFixed' in that specification.
ECMAScript 2015 (6th Edition, ECMA-262)
The definition of 'Number.prototype.toFixed' in that specification.
ECMAScript Latest Draft (ECMA-262)
The definition of 'Number.prototype.toFixed' in that specification.

Browser compatibility

Update compatibility data on GitHub
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidSafari on iOSSamsung InternetNode.js
toFixedChrome Full support YesEdge Full support 12Firefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes


Full support  
Full support

See also

दस्तावेज़ टैग और योगदानकर्ता

इस पृष्ठ के लिए योगदानकर्ता: mdnwebdocs-bot, skd1993
अंतिम अद्यतन: mdnwebdocs-bot,