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

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

问题描述

全部,

我们使用 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.

它没有在 3.0 发行说明中指定这种行为变化,尽管它似乎在问题 [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 将小数四舍五入到小数点后 5 位 - 为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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