1

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?

Pops
  • 30,199
  • 37
  • 136
  • 151
badpanda
  • 2,446
  • 5
  • 34
  • 45

2 Answers2

2

You can use DecimalFormat class. Here is an explanation

Enrique
  • 9,920
  • 7
  • 47
  • 59
2

Prefer the Swing JFormattedTextField instead; see the Java Tutorial.

rhu
  • 963
  • 5
  • 9