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

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -