NHibernate 3.0将小数点后四舍五入到小数点后五位-为什么? [英] NHibernate 3.0 rounding a decimal to 5 decimal places - why?

查看:143
本文介绍了NHibernate 3.0将小数点后四舍五入到小数点后五位-为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

全部

我们使用的是NHiberate 2.1,我们在其中存储十进制值(汇率),例如123.1234567到小数点后7位

We were using NHiberate 2.1 where we are storing decimal values (exchange rates) e.g. 123.1234567 to 7 decimal places

我们正在使用默认的映射样式来映射类型:

We are mapping the type using default mapping style:

<property name="ExchangeRate"  not-null="true" />

但是,当我们升级到NHibernate 3.0时,以上值将保存为123.1234500.

However when we upgrade to NHibernate 3.0 the value above is saved as 123.1234500.

尽管似乎确实详细说明了问题[NH-1594],十进制的默认值为DECIMAL(19,5)

It does not specify this change in behaviour in the 3.0 release notes although it does seem to detail that in issue [NH-1594], the default value for decimal is DECIMAL(19,5)

我们有一个解决方案,即指定以下映射:

We have a solution i.e. specify the following mapping:

<property name="ExchangeRate"  type="decimal(10,7) not-null="true" />

我需要知道此解决方案是解决此问题的正确方法吗? 另外,为什么行为发生功能上的变化,且舍入在2.1和3.0之间?

I need to know is this solution the right way to solve this issue? Also, why is there a functional change in behaviour with rounding between 2.1 and 3.0?

干杯

比利堆栈

推荐答案

可以,但这是更干净的IMO:

That works, but this is cleaner IMO:

<property name="ExchangeRate" precision="10" scale="7" />

属性类型暗含一个非空的十进制.

A not-null decimal is implied by the property type.

这篇关于NHibernate 3.0将小数点后四舍五入到小数点后五位-为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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