This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes NumberFormat, Currency, JTextField Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "NumberFormat, Currency, JTextField" Watch "NumberFormat, Currency, JTextField" New topic

NumberFormat, Currency, JTextField

Thomas Mcfarrow
Ranch Hand

Joined: Jul 09, 2001
Posts: 137

I want to make a JTextField that will take input in and format it accordingly to the current locale's currency. The key here is that programmatically I need to detect what locales have decimal points.

Additionally, I need the number input to start from the right.

Furthermore, I have a somewhat working model for US currency but I would like to make it generic enough for global use.

For example (US Dollar):

User Enters 2 --> JTextField shows $0.02
User Enters 3 --> JTextField shows $0.23
User Enters 4 --> JTextField shows $2.34
User Enters 5 --> JTextField shows $23.45
User Enters 6 --> JTextField shows $234.56

Ilja Preuss

Joined: Jul 11, 2001
Posts: 14112
See the class DecimalFormatSymbols. You might also want to take a look at JFormattedTextField.

The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
It is sorta covered in the JavaRanch Style Guide.
subject: NumberFormat, Currency, JTextField
Similar Threads
How to verify input in the JTextField?
Currency in JTable
how to avoid user to enter a numeric or alfanumeric input to JTextField
taking value w/o submit
Rock paper scissors project