Take it easy!

CIntとRoundの予想外結果

by achi on May.14, 2009, under プログラム

 ごく常識的に利用してきたCInt関数とRound関数。

ある日部下から指摘を受けて妙な現象に遭遇。

計算結果が期待どおりになっていないと報告を受ける。

調べてみると、「まるめ」を行っている為に期待した四捨五入とは異なる結果が格納されている事が判明した。MS-KBで調べてみると、独自の誤差を調整する目的で偶数に近い方でまるめ処理が行われているような事が記載されている。

ここでCIntとRoundが使えないことになる。

これまで信頼して利用していただけに、この結果には残念な思いが残るが、それだけ浮動小数点の扱いは慎重に行うべきだと言う事か。

ASPも.NETもオリジナルの四捨五入関数が必要だな。

念のため、現役SEにも尋ねてみた。すると返答は、

「業界では常識だよ」との事。もっと早く教えてくれよ。。。

2 comments for this entry:
  1. ibelouis

    Hello, as you may already discovered I am fresh here.
    In first steps it is really good if someone supports you, so hope to meet friendly and helpful people here. Let me know if I can help you.
    Thanks in advance and good luck! :)

  2. UnmandUnsak

    hey

    just signed up and wanted to say hello while I read through the posts

    hopefully this is just what im looking for looks like i have a lot to read.

Leave a Reply

*----* Note : *----*
Please write only in Japanese or English.
If you will post any other languages, we'll mark them as spam.

And also if a linked URI in your comments, I do not approve.
*----*----*

You must be logged in to post a comment.

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...

Archives

All entries, chronologically...