1

Possible Duplicate:
Clear trailing 0’s on a double?
Limit a double to two decimal places without trailing zeros

I have a field where a user enters a number via the keyboard (decimal numberpad), for example, "1.5". This is stored as a double.

Later when I allow the user to edit the field and present the number it is shown as "1.500000" which I don't want.

What's the most efficient method to remove these trailing zeros? I can't round the number to a specific number of decimal points because the user can enter any number they wish and it has to stay this way (it's a unit of weight).

I could split the number into an array of characters and iterate over in reverse popping off the zeros until I hit anything above 0 but I thought/hoped there was something a little more efficient in Objective C?

Thanks!

Community
  • 1
  • 1
  • 1
    possible duplicate of [Limit a double to two decimal places without trailing zeros](http://stackoverflow.com/questions/4026135/limit-a-double-to-two-decimal-places-without-trailing-zeros) Also see: [Clear trailing 0s on a double](http://stackoverflow.com/questions/2641108/clear-trailing-0s-on-a-double) – jscs Oct 27 '12 at 17:07
  • ah, you beauty, the second one is perfect. Thanks! :) – Matt Stuttard Parker Oct 27 '12 at 17:33

0 Answers0