Decima(16,5)列舍入并保存拖尾零,即使它有价值 [英] Decima(16, 5) column rounding and saving tailing zeros even its having value

查看:66
本文介绍了Decima(16,5)列舍入并保存拖尾零,即使它有价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





Iam在我的项目中使用entityframework。我在db中有一个名为Factor的列,其数据类型为十进制(16,5)可为空。



我输入了像312.3132388888888888这样的数据,它在db3中保存就像312.31000一样不确定原因。我调试了代码并看到它获得了全部值,它不是代码中的四舍五入。



看起来它正在更新2位小数,但是当使用更新查询手动更新sql数据库中的值时,它正在正确更新。



任何人都可以告诉导致问题的原因,我错过了什么吗?




在此先感谢!!!



我尝试过:



我找到了以下解决方案,但我有超过20个十进制列。还有其他解决方案我可以应用所有列吗?



Hi,

Iam using entityframework in my project. I have a column called Factor in db and its datatype is decimal(16,5) nullable.

I gave input like 312.3132388888888888 and it is saving in db like 312.31000 not sure the reason. I have debugged the code and seen its getting full value, it is not rounding in code.

It looks like it is updating 2 decimals, but when manually update the value in sql database using update query it is updating correctly.

Can any one tell what is causing the issue, am I missing anything?


Thanks in Advance!!!

What I have tried:

I have found following solution but I have more than 20 decimal columns. Is there any other solution where I can apply all columns?

protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Entity<Metrics>().Property(x => x.PPM).HasPrecision(4, 3);
    }

推荐答案

它可能连接到EF中的小数默认值,即(18,2) ...

如果你想要一些不同的东西你必须申报它,你在DB中拥有它是不够的......

所以你的解决方案是最好的你可能有......
It is probably connected to the default values of a decimal in EF, which is (18,2)...
If you want something different you have to declare it, it is not enough that you have it in the DB...
So your solution is the best you may have...


你唯一的解决办法就是为你所拥有的每一栏酌情申报。



不,没有办法在单一陈述中应用它。它根本与数据库无关,而是与你的EF模型有关。
You're only solution is to declare this, as appropriate, for each column you have.

No, there is no way to apply it in a single statement. It has nothing to do with the database at all, but everything to do with your EF model.


这篇关于Decima(16,5)列舍入并保存拖尾零,即使它有价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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