开发者

How can I output only a certain number of digits after a decimal place in a JTextComponent?

开发者 https://www.devze.com 2022-12-24 23:55 出处:网络
I am using both JLabels and JTextFields, and need to be able to truncate my doubles to two decimal places when they are displayed by the application.

I am using both JLabels and JTextFields, 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 JFormattedTextFields?


You can use DecimalFormat class. Here is an explanation


Prefer the Swing JFormattedTextField instead; see the Java Tutorial.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号