gpt4 book ai didi

Java int 乘以 float 损失精度

转载 作者:行者123 更新时间:2023-12-01 18:33:38 28 4
gpt4 key购买 nike

int totalSum = ids.length() * price;

length is int
price is float

我收到此错误:

error: possible loss of precision

如何在不损失精度的情况下正确地将 int 乘以 float?

最佳答案

因为你得到的结果是int,它将忽略小数点后的值

试试这个

double totalSum = ids.length() * price;

关于Java int 乘以 float 损失精度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23012524/

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