Scenario: I have a UISlider
that allows for values from 0 to 100. This slider will return a float
such as 76.2345654234. In core data, I want to store this percentage as a double in this format: 0.76.
Problem: Using floor()
or round()
on the float gives me 76. Good. But if I divide by 100 now pesky trailing decimals show up. Sometimes certain numbers will work and give me 2 decimal places, but without fault, every time, another number won't and I'll end up with something that looks like this: 0.760000001.
No solution I've seen on this website or otherwise works 100% of the time. Surely there must be a way do to something this simple? Thanks!!