我得到双重价值,我需要后,以减少近似值。例如:
i am getting double values,i need to reduce to approximative value after . for example
我有123.678,我需要格式化这个为124。
i have 123.678,i need to format this as 124.
如果我有123.212我需要格式化这个123
if i have 123.212 i need to format this as 123
我怎么可以这样做,任何一个可以请帮助我。
how can i done this,can any one please help me.
感谢ü提前。
听起来像是你想要的 Math.round()以浮筒或的 Math.round()双打
Sounds like you want Math.round() for floats or Math.round() for doubles
公共静态INT轮(浮动)
公共静态长圆(双A)
返回最接近INT /长到 参数。
Returns the closest int/long to the argument.
结果被舍入为 通过加入1/2,取整数 结果的地板,和铸造 结果为int类型/长。
The result is rounded to an integer by adding 1/2, taking the floor of the result, and casting the result to type int/long.
在换言之, 该结果等于的值 恩pression:(INT)Math.floor(A + 0.5F)或(长)Math.floor(A + 0.5D)
In other words, the result is equal to the value of the expression: (int)Math.floor(a + 0.5f) or (long)Math.floor(a + 0.5d)