标签:result out main round imp span res ble import
import java.math.BigDecimal; public class RoundTest { public static void main(String[] args) { double data = 56.265d; double result = new BigDecimal(data).setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue(); //1代表保留1位小数,保留两位小数就是2,依此累推 //BigDecimal.ROUND_HALF_UP 代表使用四舍五入的方式 System.out.println(result);//输出56.3 } }
标签:result out main round imp span res ble import
原文地址:https://www.cnblogs.com/nihaorz/p/11458325.html