CIntとRoundの予想外結果
by achi on May.14, 2009, under プログラム
ごく常識的に利用してきたCInt関数とRound関数。
ある日部下から指摘を受けて妙な現象に遭遇。
計算結果が期待どおりになっていないと報告を受ける。
調べてみると、「まるめ」を行っている為に期待した四捨五入とは異なる結果が格納されている事が判明した。MS-KBで調べてみると、独自の誤差を調整する目的で偶数に近い方でまるめ処理が行われているような事が記載されている。
ここでCIntとRoundが使えないことになる。
これまで信頼して利用していただけに、この結果には残念な思いが残るが、それだけ浮動小数点の扱いは慎重に行うべきだと言う事か。
ASPも.NETもオリジナルの四捨五入関数が必要だな。
念のため、現役SEにも尋ねてみた。すると返答は、
「業界では常識だよ」との事。もっと早く教えてくれよ。。。
2 comments for this entry:
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.
2月 28th, 2010 on 6:43 am
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!
7月 29th, 2010 on 10:47 pm
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.