Clear trailing 0 to double?

I have a double that got a value of something like 0.50000, but I just want 0.5 - Is there a way to get rid of these lagging 0? :)

+4
source share
2 answers

C format standard instructions

NSLog(@" %.2f", .5000) 
+5
source

In C,

 printf("%g", 0.5000); 

Note: (from the GNU libc manual)

The % g and % G conversions print an argument in the style of% e or% E (respectively) if the exponent is less than -4 or greater than or equal to accuracy ; otherwise they use the style "% f". An accuracy of 0 is assumed to be 1. Trailing zeros are removed from the fractional part of the result, and the decimal point symbol appears only if they are followed by a digit.

+13
source

Source: https://habr.com/ru/post/1306975/


All Articles