Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Number.prototype.toExponential()

此文件需要編輯審查。看看您能幫什麼忙。

翻譯不完整。請協助 翻譯此英文文件

toExponential() method 用來將數字轉成「科學計數法」格式。

語法

numObj.toExponential([fractionDigits])

參數

參數 可選 默認值 類型 說明
fractionDigits 默認盡可能將數字完整顯示 Number(正整數) 小數點後的位數。需為 0 至 20 之間。

回傳直

一 string,將數字以「科學計數法」格式表示出來

Exceptions

RangeError
若 fractionDigits 超出範圍(可接受的範圍是 0 ~ 20 之間的正整數)觸發 RangeError
TypeError
若參數 fractionDigits 不是 Number,則觸發TypeError

Description

If the fractionDigits argument is omitted, the number of digits after the decimal point defaults to the number of digits necessary to represent the value uniquely.

If you use the toExponential() method for a numeric literal and the numeric literal has no exponent and no decimal point, leave whitespace(s) before the dot that precedes the method call to prevent the dot from being interpreted as a decimal point.

If a number has more digits than requested by the fractionDigits parameter, the number is rounded to the nearest number represented by fractionDigits digits. See the discussion of rounding in the description of the toFixed() method, which also applies to toExponential().

範例

Using toExponential

var numObj = 77.1234;

console.log(numObj.toExponential());  // logs 7.71234e+1
console.log(numObj.toExponential(4)); // logs 7.7123e+1
console.log(numObj.toExponential(2)); // logs 7.71e+1
console.log(77.1234.toExponential()); // logs 7.71234e+1
console.log(77 .toExponential());     // logs 7.7e+1

Specifications

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.toExponential' in that specification.
Standard  
ECMAScript 2015 (6th Edition, ECMA-262)
The definition of 'Number.prototype.toExponential' in that specification.
Standard  
ECMAScript 2017 Draft (ECMA-262)
The definition of 'Number.prototype.toExponential' in that specification.
Draft  

瀏覽器支援度

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support (Yes) (Yes) (Yes) (Yes) (Yes)
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support (Yes) (Yes) (Yes) (Yes) (Yes) (Yes)

延伸閱讀

文件標籤與貢獻者

 此頁面的貢獻者: Shiyou
 最近更新: Shiyou,