Skip to content

Commit

Permalink
Fix float serialization on variant cultures
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchLeaders committed Jan 15, 2024
1 parent aeec6d6 commit 7964758
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/BymlLibrary/Yaml/YamlEmitter.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using BymlLibrary.Extensions;
using System.Buffers;
using System.Globalization;
using System.Text;

namespace BymlLibrary.Yaml;
Expand Down Expand Up @@ -66,7 +67,7 @@ public void EmitNode(in ImmutableByml byml, in ImmutableByml root)
else if (byml.Type == BymlNodeType.Float) {
float value = byml.GetFloat();
Builder.Append(
(value % 1) == 0 ? $"{value:0.0}" : value.ToString()
(value % 1) == 0 ? string.Format(CultureInfo.InvariantCulture, "{0}.0", value): value.ToString(CultureInfo.InvariantCulture.NumberFormat)
);
}
else if (byml.Type == BymlNodeType.UInt32) {
Expand All @@ -83,7 +84,10 @@ public void EmitNode(in ImmutableByml byml, in ImmutableByml root)
}
else if (byml.Type == BymlNodeType.Double) {
Builder.Append("!d ");
Builder.Append(byml.GetDouble());
double value = byml.GetDouble();
Builder.Append(
(value % 1) == 0 ? string.Format(CultureInfo.InvariantCulture, "{0}.0", value) : value.ToString(CultureInfo.InvariantCulture.NumberFormat)
);
}
else if (byml.Type == BymlNodeType.Null) {
Builder.Append("null");
Expand Down

0 comments on commit 7964758

Please sign in to comment.