0

I would like to round a double with 2 decimals. I have tried many ways - round * 100 /100 - by passing with a string

but it's the same matter

I would like 166.67 but I get 166.66999999 (look at the picture)

enter image description here

FREDERIC1405
  • 85
  • 1
  • 5
  • 2
    See [Is floating point math broken?](http://stackoverflow.com/questions/588004/is-floating-point-math-broken). You may choose to _present_ a double value using e.g. 2 decimals, but due to inherent limitations in how floating points are represented (stored), many real numbers cannot be represented "exactly". – dfrib Oct 20 '16 at 09:42
  • 2
    That is to be expected because a number like `166.67` *cannot* be represented exactly with a binary floating point number. Compare for example http://stackoverflow.com/questions/39770303/swift-issue-in-converting-string-to-double. – Martin R Oct 20 '16 at 09:42

0 Answers0