ios - Formatting float to show only 5 figures -
i have float number 3.553 or 34.535 or 353.6436 want no more 5 figures, before or after dot, example, first number wrote has 3.5530, sec 34.535 , 3rd 353.64.
how can nsnumberformatter?
use nsnumberformatter convert number string. specify 5 decimal digits , turn off grouping. 1 time have string, index of decimal separator. if index 4 or less (a number less 10,000), take first 6 characters of string. if index 5 or more (a number greater or equal 10,000), take first 5 characters of string.
you may have adjust depending on how want deal numbers less 1 due leading 0 ahead of decimal separator.
ios objective-c nsnumberformatter cgfloat
No comments:
Post a Comment