より良いエンジニアを目指して

1日1つ。良くなる!上手くなる!

Entries from 2020-05-01 to 1 day

浮動小数点数の比較は誤差が出る。どうすれば?

C#

浮動小数点数の比較は誤差が出ます。 class Program { static void Main(string[] args) { double a = 0; for (int i = 0; i < 10; i++) { a += 0.1d; } Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine($"{a} == 1.0d"); if (a == 1.0d) { …