I have a float number that could be 3.553 or 34.535 or 353.6436 I want it to be no more than 5 figures, before or after the dot, for example, for the first number I wrote it has to be 3.5530, for the second 34.535 as is and for the third 353.64.
How can I do that with NSNumberFormatter?
Use NSNumberFormatter
to convert the number to a string. Specify 5 decimal digits and turn off any grouping. Once you have the string, get the index of the decimal separator. If its index is 4 or less (a number less than 10,000), take the first 6 characters of the string. If its index is 5 or more (a number greater or equal to 10,000), take the first 5 characters of the string.
You may have to adjust this depending on how you want to deal with numbers less than 1 due to the leading zero ahead of the decimal separator.