Re: Sum with decimal types
- From: John B <jbngspam@xxxxxxxxx>
- Date: Fri, 29 Jul 2005 15:26:47 +1000
notifications@xxxxxxxxxxxxx wrote:
Because if you use + there an implicit convertion where it rounds to the nearest integer value.
Are you sure? When I try
decimal d1 = 4.61m; decimal d2 = 4.61m; decimal d = d1 + d2;
it works as expected.
Of course if you were to try and add int and decimal it would but decimal and decimal?
Cheers JB
If you want to sum 2 decimals you should use the static method "Add" which will undestand that you are dealing with decimal types.
System.Decimal d = System.Decimal.Add(4.61m, 4.61m); result is 9.22
HTH,
Erick Sgarbi www.blog.csharpbox.com
Actually I have two quantities (4.61) stored as decimal numbers. Why if I try to sum them the result is 9.23 if the correct value is 9.22?
Thank you
.
- References:
- Sum with decimal types
- From: Alberto
- Re: Sum with decimal types
- From: notifications
- Sum with decimal types
- Prev by Date: Need xome help on template calss library in C#
- Next by Date: RE: WinForm - DataGrid - Enter Key
- Previous by thread: Re: Sum with decimal types
- Next by thread: Re: Sum with decimal types
- Index(es):
Relevant Pages
|