This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

NumberFormat question  RSS feed

 
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a way to use NumberFormat or DecimalFormat to return an empty string for a negative number.
I see how you can specify two patterns separated by semicolons to specify +ve and -ve formatting respectively, but is there a way to just show a blank say for a negative number...

doesn't work.

Thanks

Dave
 
Ranch Hand
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm guessing you probably don't want to do this, but you might try extending them...
 
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Stephen Huey:
I'm guessing you probably don't want to do this, but you might try extending them...



I'd probably rather write a Decorator or something...
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you want to do this? It would make more sense to me to test if the number is negative before sending it to NumberFormat. Perhaps if you explain the context of this question it will help us understand your reasoning in trying to do this.

Layne
 
Dave Hewy
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just wanted to have a generic handler that I could pump in numbers and get the result for the given pattern, but in certain instances it's a requirement that if a number is -ve, it should be returned as blank, and other times if it's +ve it should be blank depending on where the number is being used, eg Accounts reports etc.

I have just encapsulated the required functioinality into another class that checks this kind of stuff for now, but thanks for your suggestions.

Dave
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!