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


Dart double.round用法及代碼示例

dart:core 庫中double.round 方法的用法介紹如下。

用法:

int round()
      override

返回最接近此數字的整數。

當沒有最接近的整數時從零開始舍入:(3.5).round() == 4(-3.5).round() == -4

如果此數字不是有限的(NaN 或無窮大),則拋出 UnsupportedError

print(3.0.round()); // 3
print(3.25.round()); // 3
print(3.5.round()); // 4
print(3.75.round()); // 4
print((-3.5).round()); // -4

相關用法


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