除以100返回0 [英] Dividing by 100 returns 0
本文介绍了除以100返回0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我只想计算增值税,但是当我除以100以获得总价格(价格*增值税/ 100)时,它会返回0.0。这是我的代码:
I just wanted to calculate the VAT, but when i divide by 100 to obtain the total price (price*VAT/100), but it returns me 0.0. Here's my code:
a.price=sc.nextInt();
a.vat=sc.nextInt();
a.total=a.precio*a.iva/100;
'total'定义为FLOAT而不是INT
'total' is defines as FLOAT instead of INT
推荐答案
您需要将表达式转换为 float
。我在这里使用了浮点字面值 100.0f
。
You need to cast the expression to float
. I used a float literal here 100.0f
.
a.total= a.precio*a.iva/100.0f;
这篇关于除以100返回0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文