Here's my problem:
The user should be able to enter a price which might be a floating point number (0.59, 1.25 etc). I want to store the price as an integer value. My original solution is Int((Float(stringPrice) ?? 0) * 100)
but there's an obvious problem with floating point numbers. For example if stringPrice
is "0.59"
the resulting integer appears to be 58
.
What is the best way to handle such a converting?
UPD: This question has been marked as a duplicate and it is in some way but I'll leave it here for one reason: if one doesn't know that this problem can be reduced to the rounding one they will find this question (also as a proxy to the reduced question) useful