JAVA舍入,截尾测试

来源:互联网 发布:网络安全教育案例视频 编辑:程序博客网 时间:2024/05/21 18:46
/**
 * 
 * @author caryt
 *
 */
public class test {
  
/**
* @param args
*/

public static void main(String[] args) {
// TODO Auto-generated method stub

//结尾:
System.out.println("舍入截尾测试:"+(int)0.6f+" : "+(int)0.7);
//舍入需要round()方法

System.out.println("舍入:"+Math.round(0.6f)+" 舍入:"+Math.round(0.7)+" 截尾:"+Math.round(0.4f)+" 截尾:"+Math.round(0.4));

}

}

out:  舍入截尾测试:0 : 0
舍入:1 舍入:1 截尾:0截尾:0

原创粉丝点击