Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
538
When applying a mask on double value, how does the grid round
posted

Hello,

I have a weird problem with rouding in the Grid and C#.

I have following number = 260.7045.

I have a mask in the column that states only 3 decimal places:

{LOC}-nn,nnn,nnn,nnn.nnn

The grid will thus display 260.705

This is the sort of result that one would expect. However, i also have a report that has to display this number correctly. In this case, because i need to do further calculation with this number, i have to round the number.

Much to my surprise the rounded number becomes 206.704 in c#.

I figured out that this is because c# uses bankers rounding, so i figured that i needed to use an override of Math.Round:

Math.Round(260.7045, 3, MidpointRounding.AwayFromZero) == 260.705

However, when i try to the following calculation:

Math.Round(141.855, 2, MidpointRounding.AwayFromZero) == 141.85

==> Why does the function not return 141.86, when you try this in the grid it will display 141.86

I realize this is a C# problem, however... my question is, how does the mask work, which function does infragistics use and can we use it too in our app, so we have a consistent way of calculation.