I want to convert a number which is input as NSString
to NSDecimalNumber
based on NSLocale.
for example
InputString => 110.50
Current Locale => en_FI
Expected output => 110.50
Actual output => 110
InputString => 110.50
Current Locale => en_US
Expected output => 110.50
Actual output => 110.50
InputString => 110,50
Current Locale => en_US
Expected output => 110.50
Actual output => 110
InputString => 110.50
Current Locale => en_US
Expected output => 110.50
Actual output => 110.50
I am using the following code to achieve this but its not working.
NSDecimalNumber *decimalNumber = [NSDecimalNumber decimalNumberWithString:self.amountTextField.text locale:[NSLocale currentLocale]];
As mentioned above in 1st and 3rd i am not the desired output. Any idea what i am doing wrong here.
I propose you to specify
NumberFormatter
sdecimalSeparator
yourself and in input string replace,
and.
with same character you used indecimalSeparator
.Same in Objective-C