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


Dart num.toStringAsFixed用法及代碼示例

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

用法:

String toStringAsFixed(
   int fractionDigits   
)

此數字的小數點string-representation。

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

如果 this 的絕對值大於或等於 10^21 ,則此方法返回由 this.toStringAsExponential() 計算的 index 表示。否則,結果是最接近的字符串表示,小數點後正好有fractionDigits 數字。如果fractionDigits 等於0,則省略小數點。

參數 fractionDigits 必須是滿足: 0 <= fractionDigits <= 20 的整數。

例子:

1.toStringAsFixed(3);  // 1.000
(4321.12345678).toStringAsFixed(3);  // 4321.123
(4321.12345678).toStringAsFixed(5);  // 4321.12346
123456789012345.toStringAsFixed(3);  // 123456789012345.000
10000000000000000.toStringAsFixed(4); // 10000000000000000.0000
5.25.toStringAsFixed(0); // 5

相關用法


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