| Author |
formatting negative integers with parentheses
|
Stephen Huey
Ranch Hand
Joined: Jul 15, 2003
Posts: 618
|
|
I need to format negative and positive integers like 23974 and -98732 in this way: 23,974 (98,732) The positive ones aren't that hard: For the negative ones, this seems to work for me: However, the DecimalFormat doc advises not to call the DecimalFormat constructors directly. Is there another/better way to do this? Also, it looks like I can't do the parentheses for negatives on percents, because I only know how to call this: And NumberFormat doesn't have those methods I used above...
|
 |
Jeanne Boyarsky
internet detective
Marshal
Joined: May 26, 2003
Posts: 26173
|
|
Stephen,
However, the DecimalFormat doc advises not to call the DecimalFormat constructors directly. Is there another/better way to do this?
For decimal format, you could use "postivePattern ; negativePattern", right? I'm not sure how to handle it for the percentages without custom logic. There must be a way though.
|
[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
|
 |
Stephen Huey
Ranch Hand
Joined: Jul 15, 2003
Posts: 618
|
|
|
Y'know, I saw that, but I wasn't sure what it was talking about. I think I was a bit too tired, because I just played some basketball and looked at that again, and I see how to use that now!
|
 |
 |
|
|
subject: formatting negative integers with parentheses
|
|
|