views:

346

answers:

2

How do I determine if the currency symbol is supposed to be on the left or right of a number using CFLocale / CFNumberFormatter in a Mac Carbon project?

I need to interface with a spreadsheet application which requires me to pass a number, currency symbol, currency symbol location and padding instead of a CStringRef created with CFNumberFormatter.

CFLocaleRef currentLocale = CFLocaleCopyCurrent();
CFTypeRef currencySymbol = CFLocaleGetValue (currentLocale, kCFLocaleCurrencySymbol);

provides me with the currency symbol as a string. But I'm lost on how to determine the position of the currency symbol...

+1  A: 

As a workaround, I have started to create a string representing a currency value and determining the position of the currency symbol by searching the string, but this sure looks fishy to me.

 CFNumberFormatterRef numberFormatter = CFNumberFormatterCreate(kCFAllocatorDefault, CFLocaleCopyCurrent(), kCFNumberFormatterCurrencyStyle);
 double someNumber = 0;
 CFStringRef asString = CFNumberFormatterCreateStringWithValue(kCFAllocatorDefault, numberFormatter, kCFNumberDoubleType, &someNumber);

...

Feel free to hit me with a rolled-up newspaper and tell me the real answer...

Hans Martin Kern
A: 

You could try inspecting the format string returned from CFNumberFormatterGetFormat. It looks like you want to search for ¤ which is \u00A4.

Colin Barrett