今天由于测试场景,利息的计算中涉及小数点的保留.保留的规则是:两位小数+四舍五入方式 使用的语言是JAVA, 看了许多网上的方法.因为最后保留的小数还会进行计算.所以我考虑最好不要保留的结果是String类型, 研究的方法有: 1.String result = String.format("%.2f", 变量名称) 2.String result = new java.text.DecimalFormat("#.00").format(变量名称) 3.double
代码 Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ --><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> &
java.lang.Math.Round()使用时候,处理方式整理,方便以后查找 /** * 测试函数 2014-01-10 */ public class TestMath { public static void main(String[] args) { System.out.println("小数点后第一位=5"); System.out.println("正数:Math.round(11.5)=" + Mat
Math.Round((n * u - t * u )/ u, f);//这里使用银行家四舍五入对应JS的 toFixed() ((n * u - t * u) / u).toFixed(f) f为小数位数. 使用中国人的四舍五入 Math.Round(System.Convert.ToDecimal((n * u - t * u) / u), f, MidpointRounding.AwayFromZero);
public static long round(double a) 返回最接近参数的 long.结果将舍入为整数:加上 1/2,对结果调用 floor 并将所得结果强制转换为 long 类型.换句话说,结果等于以下表达式的值: (long)Math.floor(a + 0.5d) 按照四舍五入的理解,-11.5约等于-12才对,但是Java中的round采取加上1/2再向下取整的方式,所以在类似这种.5的数据时不能按四舍五入理解. 又测试了下Excel表格,发现它的round函数为四舍五入.