java处理小数的精度

http://forum.java.sun.com/thread.jspa?threadID=677141&messageID=3951542
    /**
     * Scale decimal number via the rounding mode BigDecimal.ROUND_HALF_UP.
     * 
     * @param value Decimal value.
     * @param scale New scale.
     * @return Scaled number.
     * @since 1.8.3
     */
    static public double getScaled(double value, int scale) {
        double result = value; //default: unscaled
 
        //use BigDecimal String constructor as this is the only exact way for double values
        result = new BigDecimal(""+value).setScale(scale, BigDecimal.ROUND_HALF_UP).doubleValue();
        
        return result;
    }//getScaled()



http://www.javaworld.com/javaworld/jw-06-2001/jw-0601-cents.html?page=2

你可能感兴趣的:(java,thread,html,UP,sun)