舍入数到整数 [英] Round numbers to integer
问题描述
我正在寻找一种方法来计算
查询中的计算结果
fe:
在查询中执行此计算:
a / b = c
5/3 = 1,666666667 >
我希望将其四舍五入为1,即最接近的整数。怎么
我会在查询中这样做????
TIA HENRO
我正在寻找一种方法来计算
$ b $中的计算结果b查询
fe:
在查询中执行此计算:
a / b = c
5/3 = 1,666666667
我希望将其四舍五入为1,即最接近的整数。怎么
我会在查询中这样做????
您可以使用int或fix - 例如int(5/3)
要了解它的不同之处,请查看在线帮助。
问候
Jens
3月19日上午7:26,Henrootje < Hen ... @ gmail.comwrote:
我正在寻找一种方法来计算
$ b $中的计算结果b查询
fe:
在查询中执行此计算:
a / b = c
5/3 = 1,666666667
我希望将其四舍五入为1,即最接近的整数。怎么
我会在查询中这样做????
TIA HENRO
你可以做的其他事情是5 \ 3(相反方向的斜线)。
选项!!!
恕我直言,绝对是我见过的最好的舍入功能。
选项比较数据库''使用数据库顺序进行字符串比较
选项明确
全局Const vb_roundup = 1
全局Const vb_rounddown = 0
函数RoundToNearest(Amt As Double,RoundAmt As变体,方向为
整数)为双
出错时继续下一步
Dim Temp As Double
Temp = Amt / RoundAmt
如果Int(Temp)= Temp那么
RoundToNearest = Amt
否则
如果Direction = vb_rounddown然后
Temp = Int(Temp)
Else
Temp = Int(Temp)+ 1
End如果
RoundToNearest = Temp * Roun dAmt
结束如果
结束功能
===================== ===
用法:
roundtonearest(5 / 3,1,1)
结果:1
RoundToNearest(0.6723983761,.000005,0)
结果:0.672395
====== ==================
" Matt" < md ******* @ yahoo.com写了留言
新闻:11 ********************** @ l75g2000hse.googlegr oups.com ...
3月19日上午7:26,Henrootje < Hen ... @ gmail.comwrote:
我正在寻找一种方法来计算
$ b $中的计算结果b查询
fe:
在查询中执行此计算:
a / b = c
5/3 = 1,666666667
我希望将其四舍五入为1,即最接近的整数。怎么
我会在查询中这样做????
TIA HENRO
你可以做的其他事情是5 \ 3(反方向斜线)。
选项!!!
I am looking for a way to round down the results of a calculation in a
query
f.e.:
in a query this calculation is performed:
a/b = c
5/3 = 1,666666667
I would like this to be rounded to 1, the lower nearest integer. How
would I do this in a query????
TIA HENRO
Hi,
I am looking for a way to round down the results of a calculation in a
query
f.e.:
in a query this calculation is performed:
a/b = c
5/3 = 1,666666667
I would like this to be rounded to 1, the lower nearest integer. How
would I do this in a query????You can use int or fix - e.g. int(5/3)
To be aware of the differences of it take a look at the online help.
Regards
Jens
On Mar 19, 7:26 am, "Henrootje" <Hen...@gmail.comwrote:I am looking for a way to round down the results of a calculation in a
query
f.e.:
in a query this calculation is performed:
a/b = c
5/3 = 1,666666667
I would like this to be rounded to 1, the lower nearest integer. How
would I do this in a query????
TIA HENRO
Something else you could do is 5\3 (Slash in the opposite direction).
Options!!!
IMHO, absolutely the best rounding function that I have ever seen.
Option Compare Database ''Use database order for string comparisons
Option Explicit
Global Const vb_roundup = 1
Global Const vb_rounddown = 0
Function RoundToNearest(Amt As Double, RoundAmt As Variant, Direction As
Integer) As Double
On Error Resume Next
Dim Temp As Double
Temp = Amt / RoundAmt
If Int(Temp) = Temp Then
RoundToNearest = Amt
Else
If Direction = vb_rounddown Then
Temp = Int(Temp)
Else
Temp = Int(Temp) + 1
End If
RoundToNearest = Temp * RoundAmt
End If
End Function
========================
Usage:
roundtonearest(5/3,1,1)
Result:1
RoundToNearest(0.6723983761,.000005,0)
Result: 0.672395
========================
"Matt" <md*******@yahoo.comwrote in message
news:11**********************@l75g2000hse.googlegr oups.com...On Mar 19, 7:26 am, "Henrootje" <Hen...@gmail.comwrote:I am looking for a way to round down the results of a calculation in a
query
f.e.:
in a query this calculation is performed:
a/b = c
5/3 = 1,666666667
I would like this to be rounded to 1, the lower nearest integer. How
would I do this in a query????
TIA HENRO
Something else you could do is 5\3 (Slash in the opposite direction).
Options!!!
这篇关于舍入数到整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!