其他分享
首页 > 其他分享> > 保留两位小数 显示小数点后两位

保留两位小数 显示小数点后两位

作者:互联网

package com.StringExcrise;

import java.text.DecimalFormat;

public class DFormat {
public static void main(String[] args) {
//保留两位小数 显示小数点后两位
double d = 10/3.0;
System.out.println(d);
//. 表示小数点
//0和#表示数字
//保留两位小数
DecimalFormat df = new DecimalFormat(".00");
String s = df.format(d);//格式化后是字符串
System.out.println(s);

}
}

搜索

复制

标签:两位,System,小数点,小数,DecimalFormat,out
来源: https://www.cnblogs.com/wutonga/p/16271383.html