From ac2d00223f833d3b4a395c166513e4c4a7844037 Mon Sep 17 00:00:00 2001 From: atomsk-0 Date: Tue, 29 Oct 2024 19:47:35 +0200 Subject: [PATCH] Changed float & double string converters to use invariantCulture which fixes problem where some in some language's/regions . is , --- Biohazrd.CSharp/CSharpLibraryGenerator.Constants.cs | 4 ++-- Biohazrd/Expressions/DoubleConstant.cs | 6 ++++-- Biohazrd/Expressions/FloatConstant.cs | 6 ++++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Biohazrd.CSharp/CSharpLibraryGenerator.Constants.cs b/Biohazrd.CSharp/CSharpLibraryGenerator.Constants.cs index ed0262b..0d4f767 100644 --- a/Biohazrd.CSharp/CSharpLibraryGenerator.Constants.cs +++ b/Biohazrd.CSharp/CSharpLibraryGenerator.Constants.cs @@ -82,7 +82,7 @@ static bool IsBooleanType(VisitorContext context, TypeReference targetType) // https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings#the-round-trip-r-format-specifier // The explicit d suffix is not commonly used, but it makes a double constant without the a decimal point. // https://github.com/dotnet/csharplang/blob/8e7d390f6deaec0a01f690f9689ebf93903f4b00/spec/lexical-structure.md#real-literals - return $"{value:G17}d"; + return $"{value.ToString("G17", System.Globalization.CultureInfo.InvariantCulture)}d"; } } case FloatConstant floatConstant: @@ -116,7 +116,7 @@ static bool IsBooleanType(VisitorContext context, TypeReference targetType) Debug.Assert(float.IsFinite(value), $"The float must be finite at this point!"); // G9 is the recommended format specifier for round-trippable floats // https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings#the-round-trip-r-format-specifier - return $"{value:G9}f"; + return $"{value.ToString("G9", System.Globalization.CultureInfo.InvariantCulture)}f"; } } case StringConstant stringConstant: diff --git a/Biohazrd/Expressions/DoubleConstant.cs b/Biohazrd/Expressions/DoubleConstant.cs index ccf6124..837862e 100644 --- a/Biohazrd/Expressions/DoubleConstant.cs +++ b/Biohazrd/Expressions/DoubleConstant.cs @@ -1,4 +1,6 @@ -namespace Biohazrd.Expressions +using System.Globalization; + +namespace Biohazrd.Expressions { public sealed record DoubleConstant : ConstantValue { @@ -8,6 +10,6 @@ public DoubleConstant(double value) => Value = value; public override string ToString() - => Value.ToString("G17"); + => Value.ToString("G17", CultureInfo.InvariantCulture); } } diff --git a/Biohazrd/Expressions/FloatConstant.cs b/Biohazrd/Expressions/FloatConstant.cs index 809e674..7766bef 100644 --- a/Biohazrd/Expressions/FloatConstant.cs +++ b/Biohazrd/Expressions/FloatConstant.cs @@ -1,4 +1,6 @@ -namespace Biohazrd.Expressions +using System.Globalization; + +namespace Biohazrd.Expressions { public sealed record FloatConstant : ConstantValue { @@ -8,6 +10,6 @@ public FloatConstant(float value) => Value = value; public override string ToString() - => Value.ToString("G9"); + => Value.ToString("G9", CultureInfo.InvariantCulture); } }