This accepted answer does not help if I need to do math with the resulting value.
Try this: 5.02 * .06 where 5.02 is the cost of the product and .06 is the sales tax rate. Once you move the NSNumber to a Double or Float the cost value becomes 5.0199999... and don't trust Playground examples. They show the .round and *100 /100 tricks working but in compiled Swift they don't!
I am going through a nightmare of code to write a reliable rounding a Double to 2 decimal positions so I can do a calculation!
Topic:
Programming Languages
SubTopic:
Swift
Tags: