opensubscriber
   Find in this group all groups
 
Unknown more information…

a : advanced-dotnet@discuss.develop.com 26 August 2008 • 12:58AM -0400

Re: [ADVANCED-DOTNET] Converting doubles into integers without rounding errors
by Peter Vertes

REPLY TO AUTHOR
 
REPLY TO GROUP




If you are ready to make your head spin take a look at these pages:

http://en.wikipedia.org/wiki/Bankers_rounding
http://support.microsoft.com/kb/196652
http://blogs.msdn.com/ericlippert/archive/2003/09/26/53107.aspx

-Pete

On Mon, Aug 25, 2008 at 12:51 PM, Curt Hagenlocher <curt@hage...>wrote:

> On Mon, Aug 25, 2008 at 9:48 AM, Peter Ritchie
> <advanced.dotnet.discuss.develop.com@pete...> wrote:
> >
> > I would recommend something like this:
> >
> > double tempAmount = objMyObject.Amount * 100.0;
> > uint nIntAmount = Math.Round(tempAmount);
>
> Ah, *that*'s where the rounding function is hiding.
>
> Or you could just use "Math.Round(amount, 2)" to round to the second
> decimal place.
>
> --
> Curt Hagenlocher
> curt@hage...
>
> ===================================
> This list is hosted by DevelopMentor(R)  http://www.develop.com
>
> View archives and manage your subscription(s) at
> http://discuss.develop.com
>

===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Bookmark with:

Delicious   Digg   reddit   Facebook   StumbleUpon

Related Messages

opensubscriber is not affiliated with the authors of this message nor responsible for its content.