wood burning stoves 2.0*
The moose likes Java in General and the fly likes number formats Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "number formats" Watch "number formats" New topic
Author

number formats

Maha Hassan
Ranch Hand

Joined: Aug 02, 2005
Posts: 133
i need to check that the user input follows a certain format like 6.4U (number then u )

i thought about using number format but i couldnt find the method
anyhelp or ideas???
Stuart Gray
Ranch Hand

Joined: Apr 21, 2005
Posts: 410
You are along the right lines I think. You can use a NumberFormat and the setMaximumFractionDigits() and setMinimumFractionDigits() methods (same for the integer part).

The 'U' part is harder. What exactly is it used for? If it is a currency or something, you can use the setCurrency() method. If numbers always end in 'U' and nothing else, you might want to just consider ommiting it from the input. The worse is case is you might have to implement your own Format subclass.

You can then use this in conjunction with a JFormattedTextField.
Maha Hassan
Ranch Hand

Joined: Aug 02, 2005
Posts: 133
okay i ignoreg the u.. and the list now is a list of number both (positive and negative ) and i want to check that i only have numbers??
what shall i do ..i tried to extract the charachters till i form a string and parse it and if there is an error in parsing i catch it this way i know that it is not the right input
but i think it is stupid ..is there a better way?
Stuart Gray
Ranch Hand

Joined: Apr 21, 2005
Posts: 410
I agree the solutions are not ideal. You can check out this page of the Java Tutorial to see if InputVerifiers might be better for you.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: number formats
 
Similar Threads
Format String in commas
Formatting SSN...and time
exception
decimal format
storing strings in a specific format