I'm trying to get an NSNumber
out of an NSMutableArray
that's been previously manipluated as a double
and then added to the array to print out in a label (NSString
).
It's important that the number stays as an accurate representatoin of a double with no scientific notation to abbreviate the answer.
The other requirement is to have it print to maybe 15 or 16 decimal places, rounding is optional but not required.
I also do not want trailing 0's when displaying the double
I've tried the following but these do not work...
This is ok but ends the number with a . (eg: 1+1=2.
)
double test = [[data.argOperands objectAtIndex:0]doubleValue];
label.text = [NSString stringWithFormat:@"%3.2f", test];
label.text = [label.text stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:[NSString stringWithFormat:@"0"]]];
I then try something like this, which is wrong because if I do 9^99 it'll print inf
or 0.0003/4 it'll give scientific numbers instead of the value
float y = [[calcData.argOperands objectAtIndex:0]doubleValue];;
label.text = [NSString stringWithFormat:@"%g", y];
If I do the following using double it's getting close, 9^99 works, but 3.33/5 returns 0.666000 with trailing 0's
double y = [[data.argOperands objectAtIndex:0]doubleValue];
label.text = [NSString stringWithFormat:@"%f", y];
Any code examples of how to do it this way using either NSNumberFormatter
or NSDecimalNumber
would be greatly appreciated.