ios - Possibly to set float digit precision in display string dynamically without NSNumberFormatter? -
i know how format float when displaying part of nsstring (see e.g. make float show 2 decimal places) there way dynamically set number of decimal digits displayed? example, if know want int dig
digits can modify following expression format float desired?
nsstring* formattednumber = [nsstring stringwithformat:@"%.02f", myfloat];
i know can nsnumberformatter
, i'm looking more direct method.
see ieee printf specification need know format specifiers.
you want:
int dig = 4; // example nsstring *formattednumber = [nsstring stringwithformat:@"%.*f", dig, myfloat];
dig
used *
indicate number of digits after decimal point.
Comments
Post a Comment