1

I'm using a commercial third party library that is very restrictive of the formatting of numbers displayed on the screen.

the formating can only done by You can customising a String called labelFormatString on each series, for example:

donutSeries.labelFormatString = @"$%.02f";

just like printf/NSString stringWithFormat.

and of course now my requirements impose me one final tweak that I can't figure out instead of being display $123456789 I have to display them $123,456,789

Is if possible to achieve this using ONLY the string mentioned above and NOTHING ELSE (no NSNumberFormater etc).

Thanks

Jason

Alladinian
  • 34,483
  • 6
  • 89
  • 91
Jason Rogers
  • 19,194
  • 27
  • 79
  • 112

2 Answers2

2

@zahreelay He said without formatters as he can't use them. What I think it's not possible, because formatting depends on locale and some other stuff and obj-c string formatting is not exactly the same as printf's formatting specifications. Even with printf to make thousand separation work you have to set some locale:

setlocale(LC_ALL, "");
unsigned int x = 12345u;
printf("%'8u\n", x); //prints 12,345

But unfortunately this doesn't work with NSLog for ex. (just tested it)

graver
  • 15,183
  • 4
  • 46
  • 62
  • Yes, Apple's own docs ([here](https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Strings/Articles/formatSpecifiers.html)) mention the IEEE specs ([here](http://pubs.opengroup.org/onlinepubs/009695399/functions/printf.html)), so I think the issue even would warrant a bug report. – Monolo May 11 '12 at 09:28
  • 1
    Actually the magic in this example is calling 'setlocale' function and the **'** symbol in the formatter, which symbol is marked as an extension to the ISO C standard in the IEEE specifications, so it's very possible that Apple have omitted these extensions and implemented them with their formatters... – graver May 11 '12 at 09:36
-1

Look at the NSNumberFormatter class , i believe, you could achieve it using that.

e.g.

NSNumberFormatter *formatter = [NSNumberFormatter new];
[formatter setNumberStyle:NSNumberFormatterDecimalStyle]; // this line is important!

NSString *formatted = [formatter stringFromNumber:[NSNumber numberWithInteger:2000000]]

[formatter release];
Amitg2k12
  • 3,765
  • 10
  • 48
  • 97
  • 2
    and I beleive you didn't read my question... I can't use NSNumberFormater in this case because the framework doesn't allow me too. – Jason Rogers May 11 '12 at 09:16