• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Number Formatting
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Number Formatting


  • Subject: Re: Number Formatting
  • From: Esteban <email@hidden>
  • Date: Sat, 1 Dec 2001 14:04:38 -0800

That's wierd, I ran a couple of tests, myself even trying to split the 2000 into its mantissa, exponent, and whether the mantissa was negative as NSDecimalNumber decimalNumberWithMantissa:exponent:isNegative calls for.

I also used the NSScanner to scan the UnsignedLongLong as a NSDecimal and then using NSDecimalNumber decimalNumberWithDecimal, only to get the same results as David Clark.

Maybe the problem is the assumption at the use of this. NSDecimalNumber is probably not used for converting Currency (as David appears to be trying to do) between locales, and rather it is only useful for decimal numbers with decimal points (or commas depending on where you live etc) and converting the decimal representations between locales?

setting the mantissa as 123, the exponent as -2, and the isNegative as NO, properly ends up with 1.23 as it should (at least in U.S. Decimal representation)

Might NSNumberFormatter be more appropriate for currency conversion between locales? Especially if you are using NSCells to hold the unsigned long long numbers....

Anyone with any ideas? Although i'm thinking its probably a good idea to look at apple's currency converter but i think that deals with NSNumberFormatter and NSCells...

-Esteban

On Friday, November 30, 2001, at 01:15 PM, davidjclark wrote:

Hello,

Can someone clue me in on why the following code does not work ? The number returned by descriptionWithLocale: is not being formatted as it should be. For instance, if theNumber is 2000, theString is returned as 2000. It should be returning 2,000.

- ( NSString * ) _commaDelimitedSize:(UInt64) theNumber

{

NSDecimalNumber *decimalNumber;
NSString *theString;

decimalNumber = [ NSDecimalNumber numberWithUnsignedLongLong:theNumber ];
theString = [ decimalNumber descriptionWithLocale:[ [NSUserDefaults standardUserDefaults] dictionaryRepresentation ] ];

NSLog(@"The String : %@", theString );

return theString;

}

TIA,

David
_______________________________________________
cocoa-dev mailing list
email@hidden
http://www.lists.apple.com/mailman/listinfo/cocoa-dev


  • Follow-Ups:
    • Re: Number Formatting
      • From: Esteban <email@hidden>
  • Prev by Date: Re: Drawing NSImage in grayscale
  • Next by Date: Re: Number Formatting
  • Previous by thread: Re: Drawing NSImage in grayscale
  • Next by thread: Re: Number Formatting
  • Index(es):
    • Date
    • Thread