posts - 54,  comments - 1,  trackbacks - 0

Math类保留了所有用于几何学,三角学及几种一般用途的浮点函数.包括:三届函数,指数函数,舍入函数.比较常用到的有下面几个方法:

  • abs(arg) : 返回arg绝对值,arg可以是:int,long,float,double.
  Math.abs(-30.5)           == 30.5
  Math.abs(
-100.0989)   == 100.0989
  • ceil(double arg) : 返回>=arg的最小整数.
  Math.ceil(30.4)        == 31.0
  Math.ceil(
-8.0989)   == -8.0

floor(double arg) : 返回<=arg最大整数.

  Math.floor(30.4)        == 30.0
  Math.floor(
-8.0989)   == -9.0

max(x,y) : 返回x和y中的最大值.

  • min(x,y) : 返回x和y中的最小值.
  • rint(double arg) : 返回最接近arg的整数值.
  Math.rint(30.4)        == 30.0
  Math.rint(
30.5)        == 31.0
  Math.rint(
30.51)      == 31.0
  Math.rint(
-8.0989)   == -8.0
  Math.rint(
-8.5)         == -8.0
  Math.rint(
-8.5989)   == -9.0

round(arg) : 返回arg的只入不舍的最近整数值.

  Math.round(30.4)        == 30
  Math.round(
30.5)        == 31
  Math.round(
30.51)      == 31
  Math.round(
-8.0989)   == -8
  Math.round(
-8.5)         == -8
  Math.round(
-8.5989)   == -9

random() : 返回一个介于0与1之间的伪随机数.大多数情况下适应Random类产生随机数.

Math.random()   == 0.30536023864301465   // 每次结果不同

toRadians(double angle) : 将角度转换为弧度.

Math.toRadians(120.0)  == 2.0943951023931953  // 120.0 角度 = 2.0943951023931953 弧度

toDegrees(double angle) : 将弧度转换为角度.

Math.toDegrees(1)  == 57.29577951308232  // 1 弧度 = 57.29577951308232 角度
posted on 2005-09-08 10:44 ZhuJun 阅读(455) 评论(0)  编辑  收藏 所属分类: 开发手记

只有注册用户登录后才能发表评论。


网站导航:
 

蜀中人氏,躬耕于珠海

<2005年9月>
28293031123
45678910
11121314151617
18192021222324
2526272829301
2345678

常用链接

留言簿(2)

随笔分类(71)

随笔档案(54)

博客

文档

站点

论坛

搜索

  •  

积分与排名

  • 积分 - 49833
  • 排名 - 981

最新评论

阅读排行榜