为什么我将零添加到从MS Access数据库中提取的十进制值中? [英] Why is that I get zeroes added to decimal values that I am pulling from MS Access database?

查看:62
本文介绍了为什么我将零添加到从MS Access数据库中提取的十进制值中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最初是问这个

I originally asked this here, but had to ask separately.

为什么即使我只存储十进制2.01,也要从数据库中获取2.01000000之类的值?在我的数据库中,我看到它是2.01,而不是2.010000. MS Access中的字段是十进制类型,我将其本身存储为2.01.我正在拉这样的价值:

Why is it that I'm getting values like 2.01000000 from the database, even though I am storing only decimal 2.01? In my database I see it as 2.01 and not 2.010000. The field in MS Access is of type decimal, and I store it as 2.01 itself. I am pulling the value like this:

 while(reader.Read())
        Convert.ToDecimal(reader[i]);

我得到的值是2.010000000.为什么?有没有更好的方法从数据库中读取十进制值?我将字段的精度设置为28,比例因子设置为18.

I get the value as 2.010000000. Why? Is there a better approach to read decimal values from database? I have set the field's precision as 28 and scale factor as 18..

推荐答案

System.Decimal对精度内部敏感的事实有关,SQL的decimal更是如此-将其指定为类型的一部分

Related to the fact that System.Decimal is internally sensitive to degrees of precision, SQL's decimal is even more so - with it specified as part of the type.

18的小数位数和28的精度表示在数据库中小数点后将有18个有效数字. (总精度为28位数字,点后18位,前10位).

Scale of 18 and Precision of 28 means there'll be 18 significant digits after the decimal point in the database. (28 digits precision total, 18 after the point, leaves 10 before).

哪个访问恰好包含在它发送给DAO代码的表示中.

Which access happens to include in the representation it sends to the DAO code.

在完成解析时,十进制恰好要注意.

And decimal happens to note in the parsing done.

因此您可以看到这一点.

And hence you can see this.

我个人认为这是一个缺陷.小数点应将精度表示为显式属性,或者应将其隐藏.也许有一些我无法想到的理由,但我没有想到.

Personally, I think this is a flaw; either decimal should express precision as an explicit property, or it should hide it. Maybe there's some justification I can't think of, but none come to mind.

这篇关于为什么我将零添加到从MS Access数据库中提取的十进制值中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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