How can I output only a certain number of digits after a decimal place in a JTextComponent?
-
22-09-2019 - |
문제
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?
해결책
You can use DecimalFormat class. Here is an explanation
다른 팁
Prefer the Swing JFormattedTextField
instead; see the Java Tutorial.
제휴하지 않습니다 StackOverflow