iphone - Determine where is the first zero in a float number -
in app have few random float numbers. have determine, period of zero's start cut number , display in uilabel.
so, example, if have number 3.05 displayed 3.0500000 while want displayed '3.05'.
the easiest way use length limitation @"%.2f". think if want rim zeroes should use this:
nsstring* string = [[nsstring stringwithformat: @"%f", 3.05000000] stringbytrimmingcharactersinset: [nscharacterset charactersetwithcharactersinstring: @"0"]];
will return 3.05
nsstring* string = [[nsstring stringwithformat: @"%f", 3.0500100000] stringbytrimmingcharactersinset: [nscharacterset charactersetwithcharactersinstring: @"0"]];
will return 3.05001 while @"%.2f" return 3.05
you should notice rounding errors, number 3.0500000010000 string 3.05 returned.
Comments
Post a Comment