问:如何在Access 2013中对一个数字进行ROUNDUP?

时间:2015-08-13 05:27:25

标签: sql rounding ms-access-2013

对于Access 2013,我需要一种方法将任何小数转换为SQL查询中的下一个整数。

示例:

<html><body><h2>Checking your browser..<h2><script type="text/javascript" src="/aes.js" ></script><script>function toNumbers(d){var e=[];d.replace(/(..)/g,function(d){e.push(parseInt(d,16))});return e}function toHex(){for(var d=[],d=1==arguments.length&&arguments[0].constructor==Array?arguments[0]:arguments,e="",f=0;f<d.length;f++)e+=(16>d[f]?"0":"")+d[f].toString(16);return e.toLowerCase()}var a=toNumbers("f655ba9d09a112d4968c63579db590b4"),b=toNumbers("98344c2eee86c3994890592585b49f80"),c=toNumbers("d753a2b8b06e14eaba68f691c541eff7");document.cookie="__test="+toHex(slowAES.decrypt(c,2,a,b))+"; expires=Thu, 31-Dec-37 23:55:55 GMT; path=/";location.href="http://ixfa08.gigfa.com/mytime.php?ckattempt=1";</script></body></html>

在上面的查询中,查询后,1.25行应返回为2。

据我所知,Access 2013中没有ROUNDUP函数可用于SQL查询语句。

7 个答案:

答案 0 :(得分:4)

我从这个链接找到了一个ROUNDUP等价物: http://allenbrowne.com/round.html#RoundUp

  

要向上舍入到下一个最高数字,请利用Int()向下舍入负数的方式,如下所示:        - Int( - [MyField])

     

如上所示,Int(-2.1)向下舍入到-3。因此,这个表达式最多可以达到2.1到3。

     

要向上舍入到更高的分数,乘以-100,舍入,除以-100:       Int(-100 * [MyField])/ -100

语法违反直觉,但它完全符合我的预期。

答案 1 :(得分:1)

我发现在访问中对数字进行舍入的最简单方法是使用这样的舍入函数:

圆形([MyField的] +0.4,0)

例如,数字10.1变为10.5。当应用舍入函数时,它将向上舍入为11.如果数字为10.9,则添加0.4将变为11.3,其将舍入为11.

答案 2 :(得分:0)

优秀答案&#39; alextansc&#39;。这个小小的公共功能是一种享受:

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

答案 3 :(得分:0)

这也很好用

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

结束功能

实例综述(10.333,2)= 10.34

答案 4 :(得分:0)

这是一个简单易懂的方法:

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的值! 无论如何,此函数都会将最小的小数点舍入到下一个整数小数!

答案 5 :(得分:-2)

向上取整的例子:

If n > Round ( n, 0 ) then
    n = Round ( n, 0 ) + 1    
Else    
    n = Round ( n, 0 )    
End If

答案 6 :(得分:-2)

您需要做的就是使用 回合(场+0.004999,2) 要么 一轮(场+0.000499,3) ...