如何在JTextComponent中仅输出小数点后的特定位数? [英] How can I output only a certain number of digits after a decimal place in a JTextComponent?

查看:95
本文介绍了如何在JTextComponent中仅输出小数点后的特定位数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我同时使用JLabelJTextField,并且需要在应用显示它们时将我的双精度词截断为两位小数.

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.

如何执行此截断,最好不切换到JFormattedTextField s?

How can I perform this truncation, preferably without switching to JFormattedTextFields?

推荐答案

您可以使用此处是解释

You can use DecimalFormat class. Here is an explanation

这篇关于如何在JTextComponent中仅输出小数点后的特定位数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆