aspose file tools
The moose likes Java in General and the fly likes formatting negative integers with parentheses Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "formatting negative integers with parentheses" Watch "formatting negative integers with parentheses" New topic
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
    
  66

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!
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: formatting negative integers with parentheses
 
Similar Threads
formatting integer to include commas
NumberFormat question
DecimalFormat
Guidelines for 'extenders' of a class
Exception class instantiation