import java.text.DecimalFormat;
public class Test{
public static void main( String[] args ){
DecimalFormat df = new DecimalFormat( "#0.##### " );
float f1 = 5.55f;
float f2 = 5.0f;
System.out.println( df.format( f1 ) );
System.out.println( df.format( f2 ) );
}
}
public class Test{
public static void main( String[] args ){
DecimalFormat df = new DecimalFormat( "#0.##### " );
float f1 = 5.55f;
float f2 = 5.0f;
System.out.println( df.format( f1 ) );
System.out.println( df.format( f2 ) );
}
}
本文介绍了一个Java程序示例,展示了如何使用DecimalFormat类来格式化浮点数的输出,确保数值显示既准确又美观。
259

被折叠的 条评论
为什么被折叠?



