1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Convert.ToDouble(floatValue)での誤差

Posted at

浮動小数点数で誤差が出るという知識自体は持っているのに、実際出るまで忘れてることが多いですね。

Convertは意識しないで使うとたまに躓きます。

Console.WriteLine((double)1.234f);
Console.WriteLine(Convert.ToDouble(1.234f));
Console.WriteLine((double)Convert.ToDecimal(1.234f));
//出力結果
//1.23399996757507
//1.23399996757507
//1.234

こんなことにいまだに躓くので恥さらしの記事。

小数(浮動小数点数型)の計算が思った結果にならない理由と解決法
Decimal型はいつ使うか?

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?