NHibernate 3.0将小数点后四舍五入到小数点后五位

编程入门 行业动态 更新时间:2024-10-22 12:37:34
本文介绍了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将小数点后四舍五入到小数点后五位

本文发布于:2023-07-06 08:03:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1047638.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:小数点   五位   四舍五入   NHibernate

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!