B4J Question Add Tax to Price Issue

aaronk

Well-Known Member
Licensed User
Longtime User
Hi,

I can't seem to work out what I am doing wrong with the following code.

I am trying to add 10% to the Price value, but it's doesn't seem to be working and can't work out what I am doing wrong.

Code:
Dim Price As Int = 5.50
Dim PriceTax As Int
Dim PriceTotal As Int
            
PriceTax = (Price * 0.10)
PriceTotal = (Price + PriceTax)
            
Log($"Price = ${Price}"$) ' logs 5 but should be 5.50
Log($"PriceTax = ${PriceTax}"$) ' logs 0 and should log 0.55
Log($"PriceTotal = ${PriceTotal}"$) ' logs 5 and should log 6.05

Anyone know where I have gone wrong ?
 
Solution
Worked it out. I needed to use Float rather than Int.

Code:
Dim Price As Float  = 5.50
Dim PriceTax As Float
Dim PriceTotal As Float
            
PriceTax = (Price * 0.10)
PriceTotal = (Price + PriceTax)
            
Log($"Price = ${Price}"$)
Log($"PriceTax = ${PriceTax}"$)
Log($"PriceTotal = ${PriceTotal}"$)

aaronk

Well-Known Member
Licensed User
Longtime User
Worked it out. I needed to use Float rather than Int.

Code:
Dim Price As Float  = 5.50
Dim PriceTax As Float
Dim PriceTotal As Float
            
PriceTax = (Price * 0.10)
PriceTotal = (Price + PriceTax)
            
Log($"Price = ${Price}"$)
Log($"PriceTax = ${PriceTax}"$)
Log($"PriceTotal = ${PriceTotal}"$)
 
Upvote 1
Solution

DonManfred

Expert
Licensed User
Longtime User
Upvote 0
Top