数学与数学四舍五入 [英] Maths & Rounding
问题描述
简单,我很有信心。我的代码:
System.Windows.Forms.MessageBox.Show(((Int32)Math.Copiling(1966 /
100))。ToString() );
我期待20,但得到19.我做错了什么?
谢谢
-
Daisy The Cow
现在播放:Tomcraft - Loneliness [收音机]
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,
我得到了相同的结果,即使19.66应该提升到20.(也许是一个
bug? ?)无论如何,试试这个:
System.Windows.Forms.MessageBox.Show(int.Parse(Mat h.Round((decimal)1966
/100).ToString())。ToString());
HTH,
Bill P.
>
2003年7月30日星期三21:43:46 +0100,Daisy< da *** @ nospam.oops>写道:
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(Mat h.Round((decimal)1966
/100).ToString()).ToString());
HTH,
Bill P.
On Wed, 30 Jul 2003 21:43:46 +0100, Daisy <da***@nospam.oops> wrote:
简单的东西,我很有信心。我的代码:
System.Windows.Forms.MessageBox.Show(((Int32)Math。天花板(1966 /
100))。ToString());
谢谢
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
-
使用M2,Opera的革命性电子邮件客户端: http:// www.opera.com/m2/
Imho是对的。
评估的方式是:
1966/100(int / int)= int
Math.Ceiling(上面的结果,是一个int)
转换为Int32
转换为字符串。
诀窍是int / int = int是数学如何运作的一部分。
-
问候
Thomas Tomiczek
THONA Software&咨询有限公司
(微软MVP C#/。NET)
雏菊 <哒*** @ nospam.oops>在消息中写道
news:bg ********** @ linux01.dannytuppeny.com ...
Imho it is right.
The way things are evaluated is:
1966 / 100 (int/int) = int
Math.Ceiling (result from above, being an int)
Cast to Int32
Convert to string.
The trick is that int / int = int is part of how maths works.
--
Regards
Thomas Tomiczek
THONA Software & Consulting Ltd.
(Microsoft MVP C#/.NET)
"Daisy" <da***@nospam.oops> wrote in message
news:bg**********@linux01.dannytuppeny.com...
" Daisy" <哒*** @ nospam.oops>在消息中写道
新闻:bg ********** @ linux01.dannytuppeny.com ...
"Daisy" <da***@nospam.oops> wrote in message
news:bg**********@linux01.dannytuppeny.com...
简单,我很有信心。我的代码:
System.Windows.Forms.MessageBox.Show(((Int32)Math。天花板(1966 /
100))。ToString());
我期待20,但得到19.我做错了什么?
好的,1966f / 100f有效,但这看起来不对,我只想要一个
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?
ok, 1966f / 100f works, but this doesn''t seem right, I just want a
结果单个来自2个整数的分区......这是正确的吗?
-
雏菊奶牛
现在玩:Puff Daddy ft Faith Evans - 我'会想念你
resulting Single from a division of 2 integers... Is this correct??
--
Daisy The Cow
Now playing: Puff Daddy ft Faith Evans - I''ll Be Missing You
" Bill Priess" <无***** @ nospam.com>在消息中写道
news:oprs451jimcimqky @ localhost ...
"Bill Priess" <no*****@nospam.com> wrote in message
news:oprs451jimcimqky@localhost...
嗨Daisy,
我得到了相同的结果,即使19.66应该加注到20.(也许是一个
错误???)无论如何,试试这个:
System.Windows.Forms.MessageBox.Show(int.Parse(Mat h.Round((decimal)1966
/ 100).ToString())。ToString());
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(Mat h.Round((decimal)1966
/100).ToString()).ToString());
我把它缩短为:
System.Windows.Forms.MessageBox.Show(Math.Round((d ecimal)1966 /
100).ToString());
And它也有效。我只是将双方都投入到Single中来完成它,这是
的工作原理。如果只是一方(假设在分裂之前完成演员?)工作,
那可能更好:o)
-
黛西奶牛
现在玩:麦当娜 - 冰冻
I shortened it to:
System.Windows.Forms.MessageBox.Show(Math.Round((d ecimal)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
这篇关于数学与数学四舍五入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!