Skip to content

Commit d87304c

Browse files
committed
Ensure whatever edge case it is for irony not to output scientific notation in parsed numbers
1 parent b4375af commit d87304c

1 file changed

Lines changed: 28 additions & 2 deletions

File tree

src/IronyModManager.Parser/CodeParser.cs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// Created : 02-22-2020
55
//
66
// Last Modified By : Mario
7-
// Last Modified On : 02-12-2025
7+
// Last Modified On : 12-01-2025
88
// ***********************************************************************
99
// <copyright file="CodeParser.cs" company="Mario">
1010
// Mario
@@ -959,7 +959,7 @@ public string Value
959959
containsComma = true;
960960
}
961961

962-
this.value = decimal.TryParse(val, NumberStyles.Number, CultureInfo.InvariantCulture, out var result) ? result.ToString("G0", CultureInfo.InvariantCulture) : val;
962+
this.value = TryConvertDecimal(val);
963963
if (containsComma)
964964
{
965965
this.value += ",";
@@ -968,6 +968,32 @@ public string Value
968968
}
969969

970970
#endregion Properties
971+
972+
#region Methods
973+
974+
/// <summary>
975+
/// Tries the convert decimal.
976+
/// </summary>
977+
/// <param name="value">The value.</param>
978+
/// <returns>System.String.</returns>
979+
private string TryConvertDecimal(string value)
980+
{
981+
if (string.IsNullOrWhiteSpace(value))
982+
{
983+
return value;
984+
}
985+
986+
// Ensure anti scientific output is in place
987+
if (decimal.TryParse(value, NumberStyles.Number, CultureInfo.InvariantCulture, out var result))
988+
{
989+
var format = result == decimal.Truncate(result) ? "0" : "0.############################";
990+
return result.ToString(format, CultureInfo.InvariantCulture);
991+
}
992+
993+
return value;
994+
}
995+
996+
#endregion Methods
971997
}
972998

973999
#endregion Classes

0 commit comments

Comments
 (0)