精度为双数据类型,我需要8位精度 [英] Precision in Double data type, I need 8 digit precision

查看:118
本文介绍了精度为双数据类型,我需要8位精度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我参与大学项目,我必须计算比率,典型值为0.00017493xxx

I an working on a University project, where I have to calculate a ratio, a typical value is 0.00017493xxx

xxx表示三个无效数字。 

xxx means three non significant digits. 

要计算8位数,必须没有错误。我已经了解到Double数据类型会累积错误并且在计算方式上是近似的。 

我被建议使用十进制数据类型,但它在RAM上太重了而且它不是很这个问题是,我可以信任双数据类型,精确到8位数,这个数字可以存储多少> 1个数字,而不是10 ^ 56 

8 Digits are to be calculated that there must not be an error. I have learned that Double data type accumulates error and is approximate in its way of calculation. 
I have been suggested to use decimal data type but it is too heavy on RAM and furthermore it is not very vast in terms of how much >1 numbers it can store say no 10^56 

由于任何算法近似,一定不能有损失,只有例外是第8位数的四舍五入(可选)。

My question is, can I TRUST double data type for precision up to 8 digits. That there must not be loss due to any algorithmic approximation only exception is rounding (optional) of the 8th digit.

如果双倍超过我的要求,那么该限制是什么,如果它比那更小,那是什么??? 

If double has more than that what I asked then what is that limit and if it is lesser than that, what is that??? 

请澄清:)爱你们所有人:) 

Please clarify :) Love you all :) 

推荐答案

找到的一种方法是使用您知道结果应该是什么的值来设置测试并运行此类代码以查看是否获得了预期结果。单元测试非常适合。

One way to find out is to setup a test with values that you know what the result should be and run code such as this to see if you get the expected result. Unit test are great for this.

Dim number As Double = 0.00017493999
Console.WriteLine(Math.Round(number, 8, MidpointRounding.AwayFromZero))


这篇关于精度为双数据类型,我需要8位精度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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