gpt4 book ai didi

java - 四舍五入将其转换为 int (java)

转载 作者:IT老高 更新时间:2023-10-28 11:23:03 30 4
gpt4 key购买 nike

现在我正在尝试这个:

int a = round(n);

其中 ndouble 但它不起作用。我究竟做错了什么?

最佳答案

片段中round()方法的返回类型是什么?

如果这是 Math.round() 方法,当输入参数为 Double 时,它​​会返回 Long。

所以,你将不得不转换返回值:

int a = (int) Math.round(doubleVar);

关于java - 四舍五入将其转换为 int (java),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2654839/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com