# Decimal.Round function with 0 precision is rounding the decimal to nearest even number if the fractional component of the decimal is 0.5

 0 I am trying to use Decimal.Round to round a decimal value to 0 decimal precision. It's giving me different results for different decimal values. For Example Decimal.Round( 40.5, 0 ) = 40 and Decimal.Round( 41.5, 0) = 42 It may be due to the fact that Decimal.Round function with 0 precision is rounding the decimal to nearest even number if the fractional component of the decimal is 0.5. Does anyone know what I am doing anything wrong here and a solution for this? asked 30 Sep '20, 11:33 Nitin Chhabra 101●28●31●35 accept rate: 31%

 0 Graphite’s Decimal.Round system function uses Math.Round function of .net framework that has default rounding to nearest even (banker’s rounding). If you are looking to round the decimal (D) with fractional component >= 0.5 to D + 1 and <0.5 to D -1, then here is the possible solution: Create a behavior with the following logic – Use Decimal.Floor to get the floor value of decimal (D) Subtract the decimal (D) from the floor value to get the fractional component Use a decision shape to check the fractional component is >=0.5 a. If >=0.5, use Decimal.Ceiling and assign it to return value b. If <0.5, use Decimal.Floor and assign it to return value You can run this behavior from places where you expect to see the above results. Hope this helps. answered 30 Sep '20, 11:35 Nitin Chhabra 101●28●31●35 accept rate: 31%
 toggle preview community wiki

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported

Tags:

Powered By: Graphite