Lets take a look at this simple example
let formatter = NumberFormatter()
formatter.number(from: "0.945")?.decimalValue // result: 0.945
formatter.number(from: "0.94")?.decimalValue // result: 0.9399999999999999
How can I achieve that "0.94"
converts to Decimal with exact same value e.g. 0.94
?
I prefer solutions with NumberFormatter
because I want to use this String to Decimal conversion also for amounts with currency, such as "$0.94"
and "0.94€"