Re: Problem with NSDecimalNumber truncating zeros
Re: Problem with NSDecimalNumber truncating zeros
- Subject: Re: Problem with NSDecimalNumber truncating zeros
- From: Eric Hermanson <email@hidden>
- Date: Mon, 06 Jul 2009 20:14:00 -0400
First of all, this has absolutely nothing to do with NSNumberFormatter.
Second of all, the NSDecimalNumber is losing information it had when I
constructed it, which I do not want it to lose. Instead of storing an
exponent of -2 and a mantissa of 2200, it instead chooses to normalize
the values to 0 and 22, respectively. While this does provide equal
numbers as far as isEqual is concerned, I am forced to store my own
context separately if I want the number to remember the scale it had
when I constructed it. This is unfortunate.
- Eric
On Jul 6, 2009, at 6:17 PM, Keary Suska wrote:
On Jul 6, 2009, at 2:35 PM, Eric Hermanson wrote:
NSDecimalNumber *number = [NSDecimalNumber
decimalNumberWithMantissa:2200LL exponent:-2 isNegative:NO];
This results in a decimal number that is represented both
internally, and as a string, as
22
instead of the desired
22.00
Because of the functionality I am trying to achieve, I need to know
the difference between 22 and 22.00, but I can't figure out how to
get NSDecimalNumber to retain the trailing zeros. Does anyone have
advice?
You shouldn't make statements about the internal workings of API
classes that you really don't understand. Specifically the
statements about "internal representation" and "truncating" are
false. That being said, if you want to compare the string
representations of two numbers, then ensure that they are formatted
similarly. Hence, use an NSNumberFormatter, preferably the same for
both numbers.
Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden