File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

number formats

 
Maha Hassan
Ranch Hand
Posts: 133
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 410
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 133
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 410
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic