Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

DeSelby

macrumors newbie
Original poster
Sep 12, 2008
3
0
I'm trying to configure a NSNumberFormatter to show negative numbers in red. You'd think this would be simple since Apple provides a (rare) code example in the Class documentation that supposedly shows how to do this exact thing.

The code looks like this:

NSMutableDictionary *newAttrs = [NSMutableDictionary dictionary];
[newAttrs setObject:[UIColor redColor] forKey:mad:"NSColor"];
[numberFormatter setTextAttributesForNegativeValues:newAttrs];

No joy. Negative numbers are otherwise correctly formatted, but they're not red.

Then the documentation goes on to say that a more direct way of doing this is to use this code:

[numberFormatter setFormat:mad:"$#,##0.00;[Red]($#,##0.00)"];

This is even worse. Not only aren't negative number red, it actually displays the text "[Red]" in front of negative numbers.

You're my last hope before I spend a tech support issue. Does anyone know how to set negative numbers to display in red using a NumberFormatter?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.