double type of decimals, rounded to two decimal places

import java.math.BigDecimal;

public class Kewai{
public static void main(String[] args) {
double f = 3.1415927;
BigDecimal b = new BigDecimal(f);
double f1 = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
System.out.println(f1);

}


}

 

Guess you like

Origin www.cnblogs.com/lev1/p/11079812.html