setMaximumFractionDigits is not working with the following code.
NSString *input=@"80.90";
NSNumberFormatter *numberFormatter=[[NSNumberFormatter alloc] init];
[numberFormatter setNumberStyle:NSNumberFormatterDecimalStyle];
[numberFormatter setMaximumFractionDigits:2];
NSNumber *number=[numberFormatter numberFromString:input];
number gets converted to 80.90000000000001. but I have put a limit to 2 decimal places. So, how do I get number as 80.90, instead of 80.90000000000001
setMaximumFractionDigits
andsetMinimumFractionDigits
used to formatting a number. or in other words it get applied while converting a number into string i.e.stringFromNumber
. So it will not get applied when you are usingnumberFromString
As @SunilPandey mentioned
-setMaximumFractionDigits
is used for formatting a number. So You can do it like this:Output:
NumberString: 80.99