0

A float problem in iOS when indexPath.row=1

Float32 value=0.05*indexPath.row;

it returns value=0.0500000007 but it should be 0.05. How to fix this??

Milo
  • 5,041
  • 7
  • 33
  • 59
sargeras
  • 179
  • 1
  • 14

1 Answers1

3

Welcome to floating point errors.

The easiest way to fix this is just to round the number after multiplying.

You can read more about why this is happening on this random website I found on Google.

Fogmeister
  • 76,236
  • 42
  • 207
  • 306
  • 1
    thanks... even after rounding the float It was still saving 0.0500000007 but i ended up changing the way i needed... – sargeras Jul 16 '14 at 08:54