Dividing by 100 returns 0

后端 未结 6 1872
一向
一向 2021-01-17 02:13

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.pri         


        
6条回答
  •  暖寄归人
    2021-01-17 03:02

    At least on of division operands must be float or double so the result is double. Otherwise the division result is integer.

    a.total=a.precio*a.iva/100.0
    

    or if you really need float, you can skip some precision

    a.total=(float)(a.precio*a.iva/100.0)
    

提交回复
热议问题