Groups | Blog | Home
all groups > c# > july 2003 >

c# : Maths & Rounding


Bill Priess
7/30/2003 2:01:57 PM
Hi Daisy,

I got the same results, even though 19.66 should raise to 20. (Maybe a
bug???) Anyhow, try this:

System.Windows.Forms.MessageBox.Show(int.Parse(Math.Round((decimal)1966
/100).ToString()).ToString());

HTH,

Bill P.

[quoted text, click to view]



--
Daisy
7/30/2003 9:43:46 PM
Something simple, I'm sure. My code:

System.Windows.Forms.MessageBox.Show(((Int32)Math.Ceiling(1966 /
100)).ToString());

I'm expecting 20, but getting 19. What am I doing wrong?

Thanks

--
Daisy The Cow
Now playing: Tomcraft - Loneliness [Radio]

Daisy
7/30/2003 10:17:14 PM
[quoted text, click to view]

I shortened it to:

System.Windows.Forms.MessageBox.Show(Math.Round((decimal)1966 /
100).ToString());

And it worked too. I'd just done it by casting both sides to Single, which
worked. If just one side (assuming cast is done before division?) works,
that's probably better :o)
--
Daisy The Cow
Now playing: Madonna - Frozen

Stephen Alpert
7/31/2003 12:20:44 PM
[quoted text, click to view]

Nobody suggested the obvious. If you want to round, why not
(year+50)/100

/steveA


AddThis Social Bookmark Button