如何在Dart中将double转换为int? [英] How to convert a double to an int in Dart?
本文介绍了如何在Dart中将double转换为int?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下内容会产生以下错误:
The following produces the below error:
int calc_ranks(ranks)
{
double multiplier = .5;
return multiplier * ranks;
}
返回类型 double
不是方法 calc_ranks
定义的 int
。如何将/舍入为 int
?
The return type double
is not a int
, as defined by the method calc_ranks
. How do I round/cast to an int
?
推荐答案
将其环绕使用 round()
方法:
Round it using the round()
method:
int calc_ranks(ranks) {
double multiplier = .5;
return (multiplier * ranks).round();
}
这篇关于如何在Dart中将double转换为int?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文