Rounding and truncating with Double type in Java
Forums:
Double pi = 3.1415;
Double piRound = (double) Math.round(pi * 1000) / 1000;
//piRound is 3.142
Double piTrunc = Math.floor(pi * 1000) / 1000;
//piTrunc is 3.141
Double piCeil = Math.ceil(pi * 100) / 100;
//piCeil is 3.15
- Log in to post comments