代码限制精度? [英] Code To Limit Precision?

查看:74
本文介绍了代码限制精度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大约一个星期前有人发布过相同内容,但是我找不到它。


有人会提出几行代码来确保

Double的存储时间不超过八位小数值

精度?


VBA或SQL ....我'' 猜的逻辑是相同的

解决方案
于星期二,2005年5月31日8点26分58秒-0400,PeteCresswell< X @ yzInvalid>

写道:

VBA或SQL



我正在做的事情:


UPDATE SET tblReturnMonthly = tblReturnMonthly.ReturnRate

CDbl(格式


([ReturnRate],"#00000000") );


.....但是想确保我没有遗漏任何东西。

截断(而不是舍入)是可以的我。


在VBA中,尝试这个函数(也可以从查询中调用):


公共函数R2(值为变体,小数为整数)作为变体

如果不是IsNull(值)那么

如果小数> = 0然后

R2 =修正(价值* 10 ^小数+ 0.5)/ 10 ^小数

否则

R2 =价值

结束如果

否则

R2 =无空

结束如果

结束功能


Somebody posted same about a week ago, but I''m unable to find it.

Could somebody put up a few lines of code that would ensure that a
Double is stored with no more than, say, eight decimal places worth of
precision?

VBA or SQL....I''m guessing the logic is the same.

解决方案

On Tue, 31 May 2005 08:26:58 -0400, PeteCresswell <x@y.z.Invalid>
wrote:

VBA or SQL


I''m currently doing:

UPDATE tblReturnMonthly SET tblReturnMonthly.ReturnRate =
CDbl(Format


([ReturnRate],"#.00000000"));

..... but wanted to make sure I''m not missing anything.
Truncation (as opposed to rounding) is ok with me.


In VBA, try this function (which can also be called from a query):

Public Function R2(Value As Variant, Decimals As Integer) As Variant
If Not IsNull(Value) Then
If Decimals >= 0 Then
R2 = Fix(Value * 10 ^ Decimals + 0.5) / 10 ^ Decimals
Else
R2 = Value
End If
Else
R2 = Null
End If
End Function


这篇关于代码限制精度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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