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!
2 ответов
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)
}
+ 1
Thank you so much! Ipang 👍🏼👍🏼👍🏼