java保留两位小数问题: 方式一: 四舍五入 double f = 111231.5585; BigDecimal b = new BigDecimal(f); double f1 = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); 保留两位小数 --------------------------------------------------------------- 方
import java.math.BigDecimal; import java.text.DecimalFormat; import java.text.NumberFormat; public class format { double f = 111231.5585; public void m1() { BigDecimal bg = new BigDecimal(f); double f1 = bg.setScale(2, BigDecimal.ROUND_HALF_UP).doubl
4种方法,都是四舍五入,例: import java.math.BigDecimal; import java.text.DecimalFormat; import java.text.NumberFormat; public class format { double f = 111231.5585; public void m1() { BigDecimal bg = new BigDecimal(f); double f1 = bg.setScale(2, BigDecimal.ROUND
package com.oracle.pojo; import java.math.BigDecimal; import java.text.DecimalFormat; import java.text.NumberFormat; public class www { public static class format { double f = 111231.5585; public void m1() { BigDecimal bg = new BigDecimal(f); double
转载自 http://blog.csdn.net/com_stu_zhang/article/details/7214565 方法1: float f = 34.232323; BigDecimal b = new BigDecimal(f); float f1 = b.setScale(2, BigDecimal.ROUND_HALF_UP).floatValue(); // b.setScale(2, BigDecimal.ROUND
方法1: float f = 34.232323; BigDecimal b = new BigDecimal(f); float f1 = b.setScale(2, BigDecimal.ROUND_HALF_UP).floatValue(); // b.setScale(2, BigDecimal.ROUND_HALF_UP) 表明四舍五入,保留两位小数 float ft = 134.3435f; int scale = 2