设为首页 加入收藏

TOP

数学运算工具类(二)
2014-11-24 12:02:25 来源: 作者: 【 】 浏览:85
Tags:数学 运算 工具
"The scale must be a positive integer or zero");
}
BigDecimal b1 = new BigDecimal(v1);
BigDecimal b2 = new BigDecimal(v2);
return b1.divide(b2, scale, round_mode).toString();
}
public static double round(double v, int scale)
{
return round(v, scale, BigDecimal.ROUND_HALF_EVEN);
}
public static double round(double v, int scale, int round_mode)
{
if (scale < 0)
{
throw new IllegalArgumentException(
"The scale must be a positive integer or zero");
}
BigDecimal b = new BigDecimal(Double.toString(v));
return b.setScale(scale, round_mode).doubleva lue();
}
public static String round(String v, int scale)
{
return round(v, scale, BigDecimal.ROUND_HALF_EVEN);
}
public static String round(String v, int scale, int round_mode)
{
if (scale < 0)
{
throw new IllegalArgumentException(
"The scale must be a positive integer or zero");
}
BigDecimal b = new BigDecimal(v);
return b.setScale(scale, round_mode).toString();
}
public static void main(String[] args) {
System.out.println(2.21 - 2);
System.out.println(7 * 0.8);
System.out.println(subtract(312.21, 312));
System.out.println(multiply(7, 0.8));
}
}
首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇java关于Properties的使用 下一篇开发中日常操作转化工具类

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: