How can I output only a certain number of digits after a decimal place in a JTextComponent?
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开发者_如何学C 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.
精彩评论