Re: Mapping decimal rounding

26 views
Skip to first unread message

CSharper

unread,
Dec 21, 2012, 4:05:59 AM12/21/12
to nhu...@googlegroups.com
Hi,
 
rounding should be part of your domain logic and not driven by truncation or some magic rounding on the mapping level.
So best handle the rounding directly in the property setter or somewhere in the domain logic even before setting the property.
 
Otherwise you may get strange results if you use the property value for further calculations. When freshly setting the property to 112,355 and doing some calculation, e.g. *10 you get an amount of 1223,55.
But after reading the rounded value from the database, the same calculation will give you 1223,60. This violates the principle that persistence should be somewhat transparent.
 
 

Am Dienstag, 18. Dezember 2012 17:30:45 UTC+1 schrieb Iiro Rahkonen:
Hi!

I have an issue with rounding numbers to the database.

I have a mapping property and the database has datatype decimal(18,2) on the field.
<property name="Amount" column="Amount" not-null="true" precision="18" scale="2" />

I would like to add a rounding function to the property mapping so that number like 112,355 would be 112,36 instead of the result of the current truncation of the number 112,35.

Basicly use the round function in .NET or SQL Server when inserting the value. Is this possible in the mapping file or do I have to do the change everywhere where the value is inserted in the database?

Priya Chauhan

unread,
Dec 21, 2012, 4:31:15 AM12/21/12
to nhu...@googlegroups.com
--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To view this discussion on the web visit https://groups.google.com/d/msg/nhusers/-/Cl8gNWSjfyAJ.

To post to this group, send email to nhu...@googlegroups.com.
To unsubscribe from this group, send email to nhusers+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.



--
PRIYANKA
Reply all
Reply to author
Forward
0 new messages