double型强转int型--向下取整;+0.5实现四舍五入

public class test2 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		double a = 100.1;
		double b = 100.5;
		float c = 100.1f;
		float d = 100.5f;
		System.out.println((int)a);
		System.out.println((int)b);
		System.out.println(get(a));
		System.out.println(get(b));
		System.out.println(get(c));
		System.out.println(get(d));
	}

	private static int get(double n){
		return (int) (n+0.5);
	}
}

展开阅读全文

没有更多推荐了,返回首页