How can I output only a certain number of digits after a decimal place in a JTextComponent?
-
22-09-2019 - |
Question
I am using both JLabel
s and JTextField
s, and need to be able to truncate my doubles to two decimal places when they are displayed by the application.
How can I perform this truncation, preferably without switching to JFormattedTextField
s?
Solution
You can use DecimalFormat class. Here is an explanation
OTHER TIPS
Prefer the Swing JFormattedTextField
instead; see the Java Tutorial.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow