From cad9e4efa62754798178d14ca6bc826e8285caf1 Mon Sep 17 00:00:00 2001 From: Vladimir Pecanac Date: Fri, 14 Aug 2026 15:13:36 +0200 Subject: [PATCH] FloatingPointTypes: retarget net10.0, add float/double/decimal equality example --- .../FloatingPointTypes/FloatingPointTypes.csproj | 2 +- .../FloatingPointTypes/FloatingPointTypes/Program.cs | 8 +++++++- numbers-csharp/FloatingPointTypes/Tests/Tests.csproj | 10 +++++----- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/numbers-csharp/FloatingPointTypes/FloatingPointTypes/FloatingPointTypes.csproj b/numbers-csharp/FloatingPointTypes/FloatingPointTypes/FloatingPointTypes.csproj index 6a9fc36a15..95dc0bf640 100644 --- a/numbers-csharp/FloatingPointTypes/FloatingPointTypes/FloatingPointTypes.csproj +++ b/numbers-csharp/FloatingPointTypes/FloatingPointTypes/FloatingPointTypes.csproj @@ -1,7 +1,7 @@  Exe - net7.0 + net10.0 enable enable diff --git a/numbers-csharp/FloatingPointTypes/FloatingPointTypes/Program.cs b/numbers-csharp/FloatingPointTypes/FloatingPointTypes/Program.cs index a4e70f954c..4c61a8a871 100644 --- a/numbers-csharp/FloatingPointTypes/FloatingPointTypes/Program.cs +++ b/numbers-csharp/FloatingPointTypes/FloatingPointTypes/Program.cs @@ -6,4 +6,10 @@ floatingArithmetic.FloatSumAndMultiplication(0.1f, 0.5f, 10); floatingArithmetic.DoubleSumAndMultiplication(0.2D, 1.5D, 10); -floatingArithmetic.DecimalSumAndMultiplication(0.2M, 1.5M, 10); \ No newline at end of file +floatingArithmetic.DecimalSumAndMultiplication(0.2M, 1.5M, 10); + +// Why 0.1 + 0.2 does not equal 0.3: double is base-two and rounds each value, +// while decimal is base-ten and stores 0.1 exactly. +Console.WriteLine(0.1 + 0.2 == 0.3); // False +Console.WriteLine((0.1 + 0.2).ToString("R")); // 0.30000000000000004 +Console.WriteLine(0.1m + 0.2m == 0.3m); // True \ No newline at end of file diff --git a/numbers-csharp/FloatingPointTypes/Tests/Tests.csproj b/numbers-csharp/FloatingPointTypes/Tests/Tests.csproj index f3eee7fab0..68c5a6075f 100644 --- a/numbers-csharp/FloatingPointTypes/Tests/Tests.csproj +++ b/numbers-csharp/FloatingPointTypes/Tests/Tests.csproj @@ -1,7 +1,7 @@ - net7.0 + net10.0 enable enable @@ -9,13 +9,13 @@ - - - + + + runtime; build; native; contentfiles; analyzers; buildtransitive all - + runtime; build; native; contentfiles; analyzers; buildtransitive all