Sql 问:如何在Access 2013中汇总一个数字?
对于Access 2013,我需要一种在SQL查询中将任何小数取整为下一个整数的方法 例如:Sql 问:如何在Access 2013中汇总一个数字?,sql,rounding,ms-access-2013,Sql,Rounding,Ms Access 2013,对于Access 2013,我需要一种在SQL查询中将任何小数取整为下一个整数的方法 例如: SELECT ROUNDUP(NumberValues) FROM Table1 在上面的查询中,1.25的行在查询后应返回为2 据我所知,Access 2013中没有用于SQL查询语句的汇总函数 我从这个链接中找到了一个类似的综述: 要向上取整到下一个最高的数字,请利用Int()向下取整负数的方式,如下所示: -Int(-[MyField]) 如上所示,Int(-2.1)向下舍入到-3。因此,该表
SELECT ROUNDUP(NumberValues) FROM Table1
在上面的查询中,1.25的行在查询后应返回为2
据我所知,Access 2013中没有用于SQL查询语句的汇总函数 我从这个链接中找到了一个类似的综述: 要向上取整到下一个最高的数字,请利用Int()向下取整负数的方式,如下所示: -Int(-[MyField]) 如上所示,Int(-2.1)向下舍入到-3。因此,该表达式将2.1取整为3 要将其四舍五入到较高的分位数,请乘以-100,四舍五入,再除以-100: Int(-100*[MyField])/-100
语法与我的直觉相反,但它的工作原理与我的预期完全一致。我从这个链接中找到了一个类似的综述: 要向上取整到下一个最高的数字,请利用Int()向下取整负数的方式,如下所示: -Int(-[MyField]) 如上所示,Int(-2.1)向下舍入到-3。因此,该表达式将2.1取整为3 要将其四舍五入到较高的分位数,请乘以-100,四舍五入,再除以-100: Int(-100*[MyField])/-100
语法是反直观的,但它的工作原理与我的预期完全一致。我发现在access中对数字进行四舍五入的最简单方法是使用如下四舍五入函数: 圆形([MyField]+0.4,0)
例如,数字10.1随后变为10.5。应用舍入函数时,它最多舍入11。如果数字是10.9,则加0.4将变成11.3,这将四舍五入为11。我发现在access中对数字进行四舍五入的最简单方法是使用如下四舍五入函数: 圆形([MyField]+0.4,0)
例如,数字10.1随后变为10.5。应用舍入函数时,它最多舍入11。如果数字是10.9,加上0.4变成11.3,四舍五入为11。非常好的答案“alextansc”。这项小小的公共活动是一种享受:
Public Function GlblRoundup(wNumber As Currency, wDecPlaces As Integer) As Currency
Dim wResult As Currency
Dim wFactor As Currency
Select Case wDecPlaces
Case 0
wFactor = -1
Case 1
wFactor = -10
Case 2
wFactor = -100
Case 3
wFactor = -1000
Case 4
wFactor = -10000
Case Else
wFactor = -10000
End Select
wResult = Int(wFactor * wNumber) / wFactor
GlblRoundup = Round(wResult, wDecPlaces)
End Function
很好的答案是“阿列克斯坦斯”。这项小小的公共活动是一种享受:
Public Function GlblRoundup(wNumber As Currency, wDecPlaces As Integer) As Currency
Dim wResult As Currency
Dim wFactor As Currency
Select Case wDecPlaces
Case 0
wFactor = -1
Case 1
wFactor = -10
Case 2
wFactor = -100
Case 3
wFactor = -1000
Case 4
wFactor = -10000
Case Else
wFactor = -10000
End Select
wResult = Int(wFactor * wNumber) / wFactor
GlblRoundup = Round(wResult, wDecPlaces)
End Function
这也很有效
Public Function roundUp(dValue As Double, idecimal As Integer) As Double
Dim iSign As Integer
If dValue < 0 Then
iSign = -1
Else
iSign = 1
End If
dValue = Abs(dValue)
If Round(dValue, 0) = 0 Then
roundUp = 1 / 10 ^ idecimal * iSign
Else
roundUp = Round(dValue + 4 / 10 ^ (idecimal + 1), idecimal) * iSign
End If
Public Function roundUp(d值为Double,理想值为Integer)为Double
Dim iSign为整数
如果dValue<0,则
iSign=-1
其他的
iSign=1
如果结束
D值=绝对值(D值)
如果四舍五入(D值,0)=0,则
综合=1/10^理想*iSign
其他的
舍入=舍入(D值+4/10^(理想+1),理想)*iSign
如果结束
端函数
示例汇总(10.333,2)=10.34这也很有效
Public Function roundUp(dValue As Double, idecimal As Integer) As Double
Dim iSign As Integer
If dValue < 0 Then
iSign = -1
Else
iSign = 1
End If
dValue = Abs(dValue)
If Round(dValue, 0) = 0 Then
roundUp = 1 / 10 ^ idecimal * iSign
Else
roundUp = Round(dValue + 4 / 10 ^ (idecimal + 1), idecimal) * iSign
End If
Public Function roundUp(d值为Double,理想值为Integer)为Double
Dim iSign为整数
如果dValue<0,则
iSign=-1
其他的
iSign=1
如果结束
D值=绝对值(D值)
如果四舍五入(D值,0)=0,则
综合=1/10^理想*iSign
其他的
舍入=舍入(D值+4/10^(理想+1),理想)*iSign
如果结束
端函数
示例汇总(10.333,2)=10.34这里有一个简单易懂的示例:
Public Function roundUp(ByVal theValue As Long) As Integer
Dim tempInt As Integer
tempInt = theValue 'cast value to whole integer
If (tempInt = theValue) Then 'check if original value was already whole
'do nothing
Else
tempInt = tempInt + 1 'value was not whole integer, add one to round up
End If
roundUp = tempInt 'return rounded value
End Function
注:
在调用函数之前,不要忘记检查您的值是否为null!
此函数将从最小的小数点到最大的小数点取整为下一个整数 这里有一个简单易懂的例子:
Public Function roundUp(ByVal theValue As Long) As Integer
Dim tempInt As Integer
tempInt = theValue 'cast value to whole integer
If (tempInt = theValue) Then 'check if original value was already whole
'do nothing
Else
tempInt = tempInt + 1 'value was not whole integer, add one to round up
End If
roundUp = tempInt 'return rounded value
End Function
注:
在调用函数之前,不要忘记检查您的值是否为null!
此函数将从最小的小数点到最大的小数点取整为下一个整数 整数取整示例:
If n > Round ( n, 0 ) then
n = Round ( n, 0 ) + 1
Else
n = Round ( n, 0 )
End If
整数四舍五入示例:
If n > Round ( n, 0 ) then
n = Round ( n, 0 ) + 1
Else
n = Round ( n, 0 )
End If
你所需要做的就是使用 四舍五入(字段+0.004999,2) 或 四舍五入(字段+0.000499,3)
…你所需要做的就是使用 四舍五入(字段+0.004999,2) 或 四舍五入(字段+0.000499,3)
…我认为,如果您处理的是超过一个小数点,那么这将不起作用。0.01+0.4=0.41,仍然向下舍入。我想你可以使用0.49999999…如果你处理的是一个以上的小数点,我认为这不起作用。0.01+0.4=0.41,仍然向下舍入。我猜您可以使用0.49999999…无法正常工作(添加缺少的End Function语句后):roundUp(1.01,1)返回1,但从我的角度来看应该返回1.1。无法正常工作(添加缺少的End Function语句后):roundUp(1.01,1)返回1,但从我的角度来看应该返回1.1。