當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Dart num.toStringAsExponential用法及代碼示例

dart:core 庫中num.toStringAsExponential 方法的用法介紹如下。

用法:

String toStringAsExponential(
   [int? fractionDigits]   
)

此數字的 index string-representation。

在計算字符串表示之前將此數字轉換為 double

如果給出fractionDigits,那麽它必須是一個滿足:0 <= fractionDigits <= 20的整數。在這種情況下,字符串在小數點後正好包含fractionDigits。否則,如果沒有該參數,則返回的字符串將使用準確表示此數字的最短位數。

如果fractionDigits 等於0,則省略小數點。例子:

1.toStringAsExponential();       // 1e+0
1.toStringAsExponential(3);      // 1.000e+0
123456.toStringAsExponential();  // 1.23456e+5
123456.toStringAsExponential(3); // 1.235e+5
123.toStringAsExponential(0);    // 1e+2

相關用法


注:本文由純淨天空篩選整理自dart.dev大神的英文原創作品 toStringAsExponential method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。