I want to convert currency to double value
In My app I have a textField which displays Currency Like
$1,234,567.00
I can Easily remove the $ sign by substrings
But Is there any Formatter style that can make it to the Double? Actually when I am doing
vardouble=[txtfield.text doublevalue];
because of comma it shows 1.00(above value).
I would suggest you to use NSNumberFormatter
.
NSNumberFormatter *nf = [[NSNumberFormatter alloc] init];
[nf setNumberStyle:NSNumberFormatterCurrencyStyle];
double d = [[nf numberFromString:@"$1,234,567.00"] doubleValue];
1) First remove commas using - (NSString *)stringByReplacingOccurrencesOfString:(NSString *)target withString:(NSString *)replacement;
2) then Call [yourString doubleValue]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With