java 保留小数点后2位
来源:学生作业帮 编辑:大师作文网作业帮 分类:综合作业 时间:2024/11/20 16:53:59
java 保留小数点后2位
/**
* Write a description of class Cylinder here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Cylinder
{
// instance variables - replace the example below with your own
private double radius;
private double height;
/**
* Constructor for objects of class Cylinder
*/
public Cylinder(double r, double h)
{
// initialise instance variables
radius = r;
height = h;
double newBase = base();
System.out.println(" the value of the base is: " + newBase);
double newCirc = circumference();
System.out.println(" the value of the Circ is: " + newCirc);
}
public double base()
{
double answer= Math.PI * radius * radius;
return answer;
}
public double circumference()
{
double answer=Math.PI * radius;
return answer;
}
}
保留2位小数
/**
* Write a description of class Cylinder here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Cylinder
{
// instance variables - replace the example below with your own
private double radius;
private double height;
/**
* Constructor for objects of class Cylinder
*/
public Cylinder(double r, double h)
{
// initialise instance variables
radius = r;
height = h;
double newBase = base();
System.out.println(" the value of the base is: " + newBase);
double newCirc = circumference();
System.out.println(" the value of the Circ is: " + newCirc);
}
public double base()
{
double answer= Math.PI * radius * radius;
return answer;
}
public double circumference()
{
double answer=Math.PI * radius;
return answer;
}
}
保留2位小数
DecimalFormat df = new DecimalFormat("0.00");
double d = 123.9078;
double db = df.format(d);
则db=123.90;
double d = 123.9078;
double db = df.format(d);
则db=123.90;
Excel公式计算时怎么保留小数点后2位
excel 函数计算怎么保留小数点后2位阿?
asp 中保留小数点后2位,小数点后第三位只要有就向前进一位
如何设置excel函数公式结果小数点后只保留2位
在excel中如何在小数点后保留2位小数?
四舍五入是怎么计算的648,09465保留小数点后2位数字
如何设置,以使EXCEL表格计算值(商)保留小数点后2位?
matlab 用num2str函数如何保留小数点后10位
85.76转换成二进制(小数点后保留3位)
物理中小数点后通常保留几位小数?
EXCEL中设置小数点后保留两位的问题,
如何在Oracle数据库中保留小数点后两位 而且在java中保留两位插入到数据表中