Access中的天花板功能

时间:2009-11-21 16:49:08

标签: excel ms-access math vba ms-office

搜索过这个,没有运气。

有人可以告诉我如何在MS访问中创建一个与excel中的天花板功能相同的天花板功能吗?

5 个答案:

答案 0 :(得分:11)

由于Int()似乎像Floor()一样工作,你可以像这样得到Ceiling:     -int(-x)

答案 1 :(得分:8)

此答案使用VBA进行访问,源自http://www.tek-tips.com/faqs.cfm?fid=5031

Public Function Ceiling(ByVal X As Double, Optional ByVal Factor As Double = 1) As Double
    ' X is the value you want to round
    ' Factor is the optional multiple to which you want to round, defaulting to 1
    Ceiling = (Int(X / Factor) - (X / Factor - Int(X / Factor) > 0)) * Factor
End Function

请注意,对于负X,此答案在数学上是正确的。有关背景,请参阅http://en.wikipedia.org/wiki/Floor_and_ceiling_functions#Spreadsheet_software

答案 2 :(得分:2)

谢谢,marg,答案。为了将来参考,这是我在导入Microsoft Excel对象库后编写的VBA函数:

Public Function Ceiling(Value As Double, Significance As Double) As Double
    Ceiling = Excel.WorksheetFunction.Ceiling(Value, Significance)
End Function

然后在我的查询中,我试图计算实际工作时间的计费小时数,然后四舍五入到下一个小时:

SELECT Ceiling(([WorkTimes]![EndTime]-[WorkTimes]![BeginTime])*24,0.25) AS BillableTime
FROM WorkTimes;

答案 3 :(得分:1)

您可以添加对Microsoft Excel对象库的引用并使用Excel.WorksheetFunction.Ceiling

答案 4 :(得分:-1)

虽然这个问题特别要求Access这里是VB.NET的答案

Public Function Ceiling(ByVal value As Double, ByVal factor As Double) As Double
    Return Math.Ceiling(value / factor) * factor
End Function

C#中的答案

public double Ceiling(double value, double factor)
{
    return Math.Ceiling(value / factor) * factor;
}

我在这里发布它是因为我需要这样的功能谷歌发送给我这个问题,但我找不到.Net的答案。我终于为自己想出来了。