开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜