相关疑难解决方法(0)

如何在Dart中将双精度舍入到小数点后的给定精度?

给定一个double,我想将它舍入到小数点后的给定数量的精度,类似于PHP的round()函数.

我在Dart文档中找到的最接近的东西是double.toStringAsPrecision(),但这不是我需要的,因为它包括精度总点数小数点之前的数字.

例如,使用toStringAsPrecision(3):

0.123456789 rounds to 0.123  
9.123456789 rounds to 9.12  
98.123456789 rounds to 98.1  
987.123456789 rounds to 987  
9876.123456789 rounds to 9.88e+3
Run Code Online (Sandbox Code Playgroud)

随着数量的增加,我在小数位后相应地失去了精度.

precision double-precision dart

49
推荐指数
15
解决办法
3万
查看次数

如何在Dart中将double转换为int?

以下产生以下错误:

int calc_ranks(ranks)
{
  double multiplier = .5;
  return multiplier * ranks;
}
Run Code Online (Sandbox Code Playgroud)

返回类型'double'不是'int',由方法'calc_ranks'定义

如何舍入/强制转换为int?

dart

44
推荐指数
6
解决办法
3万
查看次数

Dart中的Math.round()在哪里?

我没有办法在Dart中找到一个数字?

import 'dart:math';

main() {
  print(Math.round(5.5)); // Error!
}
Run Code Online (Sandbox Code Playgroud)

http://api.dartlang.org/docs/bleeding_edge/dart_math.html

dart

32
推荐指数
2
解决办法
1万
查看次数

如何在 Flutter 中取整一个数字?

Flutter 中如何将数字四舍五入到最接近的整数?

  • 0.1 => 1
  • 1.5 => 2
  • -0.1 => -1

Numround方法四舍五入到最接近的整数。怎么总能四舍五入?

dart flutter

7
推荐指数
2
解决办法
2433
查看次数

标签 统计

dart ×4

double-precision ×1

flutter ×1

precision ×1