Mega Code Archive

 
Categories / Java Tutorial / Swing
 

A decimal number with one digit following the decimal point

import java.text.DecimalFormat; import javax.swing.JFormattedTextField; public class Main {   public static void main(String[] argv) throws Exception {     JFormattedTextField tft2 = new JFormattedTextField(new DecimalFormat("#.0"));     tft2.setValue(new Float(123.4F));     // Retrieve the value from the text field     Float floatValue = (Float) tft2.getValue();   } }