Reputation: 33
I am facing issue in double to string conversion it occurs one or two users iPhone , from my side it is working as expected
my double value - 10.890000000000001,
expected string output = "10.89",
but some of users iPhone the output is - "1089" ( . is missed)
in debugging I cannot reproduce this, it working as expected, I didn't find any cause of this issue, here I attached my code, Thanks in Advance
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
[formatter setMaximumFractionDigits:2];
[formatter setRoundingMode: NSNumberFormatterRoundCeiling];
NSString *numberString = [formatter stringFromNumber:[NSNumber numberWithDouble:doubleValue]];
Upvotes: 0
Views: 98
Reputation: 487
This might not be the best practice but you can try following, it should work for you.
double doubleValue = 10.89;
NSString * numberString = [NSString stringWithFormat:@"%.02f", doubleValue];
NSLog(@"numberString = %@", numberString);
Upvotes: 0