0

Basic question

Hi I’m a rookie here. I’m trying to play around and I was expecting to get a result of 3.5 but it still shows 3. Could someone kindly explain and help ? var MOQ = 500 var price = 3 if MOQ < 1000 { let pricemarkup = 0.5 price = price + Int(pricemarkup) print(price) } Thank you!

24th Sep 2020, 11:17 PM
NAT SUN
NAT SUN - avatar
2 odpowiedzi
0
var MOQ = 500 var price = 3.0 // use of fraction defines <price> type as Double if MOQ < 1000 { let pricemarkup = 0.5 // <pricemarkup> type is Double. It is necessary // that both <price> and <pricemarkup> belong // to the same type price += pricemarkup // same as price = price + pricemarkup print(price) }
25th Sep 2020, 12:20 AM
Ipang
+ 1
Thank you so much! Ipang 👍🏼👍🏼👍🏼
25th Sep 2020, 6:29 AM
NAT SUN
NAT SUN - avatar