Thursday, 19 September 2013

Math.round is not working as i want to

Math.round is not working as i want to

Whenever a double is returned from the calculateVolume() it gets a value
for example 1.0, this need to be displayed as 1.00 (2 decimals instead of
1). It's probably quite easy but i'm not seeing what i'm doing wrong right
now. Can someone help me out and give a short explanation. Thanks a lot!
public class Block extends Shape {
private double length;
private double width;
private double height;
public Block(double length, double width, double height){
this.length = length;
this.width = width;
this.height = height;
}
@Override
public double calculateVolume(){
return Math.round((length * width * height)* 100.0) / 100.0;
}

No comments:

Post a Comment