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
Java中double类型的数据精确到小数点后两位 多余位四舍五入,四种方法 一: double f = 111231.5585;BigDecimal b = new BigDecimal(f); double f1 = b.setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue(); 二: new java.text.DecimalFormat("#.00").format(3.1415926) 三: double d = 3.1415926
取余判断原则:取余用偶判断,不要用奇判断 先看一个 程序: package com.test; import java.util.Scanner; public class t1 { public static void main(String[] args) { //接收键盘输入 Scanner in = new Scanner(System.in); while(in.hasNextInt()){ int i = in.nextInt(); System.out.println(i%2==1
package ltb6w1; import java.io.*; public class TestMod { String st; int c; InputStreamReader is=new InputStreamReader(System.in); BufferedReader bf=new BufferedReader(is); public TestMod() throws IOException { System.out.println("请输入整数:"); while
http://blog.csdn.net/huaishuming/article/details/17752365 ********************************************************** 4种方法,都是四舍五入,例: import java.math.BigDecimal; import java.text.DecimalFormat; import java.text.NumberFormat; public class format { doub
java从Object类型转换为double类型: Map<String,Object> map = new HashMap<String,Object>(); map.put("order",1.245); BigDecimal order = (BigDecimal)map.get("order"); double d = (order==null?0:order.doubleValue());
取余判断原则:取余用偶判断,不要用奇判断 先看一个 程序: package com.test; import java.util.Scanner; public class t1 { public static void main(String[] args) { //接收键盘输入 Scanner in = new Scanner(System.in); while(in.hasNextInt()){ int i = in.nextInt(); System.out.println(i%2==1