如何调整双重价值后近似值 [英] how adjust double value to approximate value after

查看:126
本文介绍了如何调整双重价值后近似值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到双重价值,我需要后,以减少近似值。例如:

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)

这篇关于如何调整双重价值后近似值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆