摘要: Math类提供了五个整数化相关函数: ceil、floor、rint、round和round
| |目录1概述2示例1概述
Math类有五个与整数化相关的函数,如下所示:
staticdoubleceil(doublea ) :天花板函数,返回大于或等于a的最小整数。 但是,它存储为浮点数。
staticdoublefloor(doublea ) :地板函数,返回a以下的最大整数。 但是,它被存储为浮点数。
staticdoublerint(doublea ) :将函数四舍五入,返回最接近a值的整数。 但是,它存储为浮点数。
staticlonground(doublea ) :将函数四舍五入,返回最接近a值的长整数数。
saticintround(floata ) :对函数进行四舍五入,返回最接近a值的整数数。
2示例Java|复制1234568101121314151617181920 package net.xsoft lab.baike; import java.util.Scanner; public class math _ round { publicstaticvoidmain (string args [ ] ) { double num; sannerin=newscanner(system.in; System.out.print ('请输入浮点数:'); num=in.nextDouble (; 双精度cnum=math.ceil (num; System.out.println ('大于' num '的最小数量: ' cnum ); 双精度fnum=math.floor (num ); System.out.println; 双精度=math.rint (num ); 基于system.out.println(num )四舍五入的浮点数(rnum ); longlnum=math.round(num ); system.out.println(num )四舍五入得到长整数(lnum ); }转载于:https://www.cn blogs.com/wxmdevelop/p/5644053.html