向上舍入数字 [英] Round up Number

查看:116
本文介绍了向上舍入数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好....

鉴于:总计= 18.01

我使用FormatNumber(总计,2),它给我18.01

我使用FormatNumber(总数,0)它给我18


我想得到19,我该怎么做代码?如果有任何十进制值

值,我想把它四舍五入到下一个整数


欢呼


***通过开发人员指南 http://www.developersdex.com 发送***

不要只参加USENET ......获得奖励!

Hi all....
Given: total = 18.01
I use FormatNumber(total,2), it give me 18.01
I use FormatNumber(total,0) it give me 18

I wanna to get 19, how should i do the code?? if there is any decimal
value, i wanna round it up to the next whole number

cheers

*** Sent via Developersdex http://www.developersdex.com ***
Don''t just participate in USENET...get rewarded for it!

推荐答案

功能RoundUp(n)

roundUp = Int(n) - CBool​​(CDbl(n)<> CLng(n))

结束功能


这可能有用。那个尝试做的是取你的

数的整数部分,18,然后,取你原来的十进制数,把它比作一个

整数版本如果它们不相同,则从结果中减去-1(假)




雷在家


< D>在留言新闻中写道:Oi ************** @ TK2MSFTNGP10.phx.gbl ...
Function RoundUp(n)
roundUp = Int(n) - CBool(CDbl(n) <> CLng(n))
End Function

That may work. What that''s trying to do is take the integer portion of your
number, 18, and then, take your original decimal number, compare it to a
integerized version of it, and if they are not the same, subtract -1 (false)
from the result.

Ray at home

<D> wrote in message news:Oi**************@TK2MSFTNGP10.phx.gbl...
大家好......
鉴于:总数= 18.01
我使用FormatNumber(总计,2),它给我18.01
我使用FormatNumber(总数,0)它给我18

我想得到19,怎么样我应该做代码?如果有任何十进制值,我想把它四舍五入到下一个整数

欢呼

***通过Developersdex发送 http://www.developersdex.com ***
不要只是参加USENET .. .get奖励它!
Hi all....
Given: total = 18.01
I use FormatNumber(total,2), it give me 18.01
I use FormatNumber(total,0) it give me 18

I wanna to get 19, how should i do the code?? if there is any decimal
value, i wanna round it up to the next whole number

cheers

*** Sent via Developersdex http://www.developersdex.com ***
Don''t just participate in USENET...get rewarded for it!



你必须处理负数吗?如果没有那么


如果总计> FormatNumber(总计,0)然后

总计= FormatNumber(总计,0)+ 1

结束如果


干杯

Ken


< D>在留言新闻中写道:Oi ************** @ TK2MSFTNGP10.phx.gbl ...
Do you have to deal with negative numbers? If not then how about:

If total > FormatNumber(total,0) then
total = FormatNumber(total,0) + 1
End If

Cheers
Ken

<D> wrote in message news:Oi**************@TK2MSFTNGP10.phx.gbl...
大家好......
鉴于:总数= 18.01
我使用FormatNumber(总计,2),它给我18.01
我使用FormatNumber(总数,0)它给我18

我想得到19,怎么样我应该做代码?如果有任何十进制值,我想把它四舍五入到下一个整数

欢呼

***通过Developersdex发送 http://www.developersdex.com ***
不要只是参加USENET .. .get奖励它!
Hi all....
Given: total = 18.01
I use FormatNumber(total,2), it give me 18.01
I use FormatNumber(total,0) it give me 18

I wanna to get 19, how should i do the code?? if there is any decimal
value, i wanna round it up to the next whole number

cheers

*** Sent via Developersdex http://www.developersdex.com ***
Don''t just participate in USENET...get rewarded for it!



谢谢。我不是处理wif neg数字所以代码工作正常。谢谢

很多


欢呼


***通过Developersdex发送 http://www.developersdex.com ***

不要只参加USENET。 ..得到奖励!
thanks. i''m not dealing wif neg number so teh code works fine. thanks
alot

cheers

*** Sent via Developersdex http://www.developersdex.com ***
Don''t just participate in USENET...get rewarded for it!


这篇关于向上舍入数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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