Question

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 I perform this truncation, preferably without switching to JFormattedTextFields?

Was it helpful?

Solution

You can use DecimalFormat class. Here is an explanation

OTHER TIPS

Prefer the Swing JFormattedTextField instead; see the Java Tutorial.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top