简体   繁体   English

Ms Access 数据库字段丢失小数点右侧数字

[英]Ms Access Database Field losing decimal right side digits

I want to store decimal value into my field when you divide我想在除法时将十进制值存储到我的字段中

1120/90 = 12.444444444444444444444444444444

This long but I am losing right side digits, I am only getting 13 right side digits - like that:这么长但我丢失了右侧数字,我只得到 13 个右侧数字 - 就像这样:

12.4444444444444

But when I multiply this back again:但是当我再次乘以它时:

12.4444444444444 x 90 = 1119.999999999996

This is not the correct answer;这不是正确的答案; the correct answer is正确答案是

12.444444444444444444444444444444 x 90 = 1120

Please help me here.请在这里帮助我。

Thanks谢谢

You can use Decimal for this:您可以为此使用Decimal

? CDec(1120) / CDec(90)
 12.444444444444444444444444444 

? (CDec(1120) / CDec(90)) * 90
 1120 

I banged on this for a long time but couldn't find a way to prove the following.我为此敲了很长时间,但找不到方法来证明以下内容。 assuming any operands can be cast to the integer type without loss of information (1120 & 90 can) then you usually must do the calculation simultaneously: The floating point division operator / handles integer like operands correctly but returns the type double.假设任何操作数都可以转换为 integer 类型而不会丢失信息(1120 和 90 可以),那么您通常必须同时进行计算:浮点除法运算符 / 像操作数一样正确处理 integer 但返回类型为 double。 chained operations are also handled correctly if done all at once.如果一次完成,链式操作也能正确处理。 Hence (1120/90) * 90 is calculated correctly as 1120 but also, typename(1120/90*90) returns the double datatype.因此 (1120/90) * 90 被正确计算为 1120,而且 typename(1120/90*90) 返回 double 数据类型。 if you store the intermediate value 1120/90 you get a double of 12.44444 repeating which isn't quite 1120/90.如果您存储中间值 1120/90,您将得到 12.44444 的两倍重复,这不完全是 1120/90。
My suggestion is to store both the operands rather than reducing them to one number.我的建议是存储两个操作数而不是将它们减少为一个数。 Then do the calculation all at once.然后一次全部计算。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM