How can I convert all numbers that are more than 3 digits down to a 4 digit or less number?
This is exactly what I mean:
10345 = 10.3k
10012 = 10k
123546 = 123.5k
4384324 = 4.3m
Rounding is not entirely important, but an added plus.
I have looked into NSNumberFormatter but have not found the proper solution, and I have yet to find a proper solution here on SO. Any help is greatly appreciated, thanks!
Here are two methods I have come up with that work together to produce the desired effect. This will also automatically round up. This will also specify how many numbers total will be visible by passing the int dec.
Also, in the float to string method, you can change the
@"%.1f"
to@"%.2f"
,@"%.3f"
, etc to tell it how many visible decimals to show after the decimal point.Hope this helps anyone else out who needs it!