Dividing by 100 returns 0

后端 未结 6 1919
一向
一向 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:10

    You have to cast your integers, otherwise your result will be computed as an integer before being assigned to a.total. Something like:

    a.total = (float)(a.precio) * (float)(a.iva) / 100;
    

提交回复
热议问题