Fix DecimalPropertyEditor on non-English systems (#20215)

* Directly convert from double or float when possible. Also fixes string parsing to work on all cultures. Fixes #20214

* Added unit tests to verify behaviour.

---------

Co-authored-by: Andy Butland <abutland73@gmail.com>
This commit is contained in:
Asbjørn Riis-Knudsen
2025-09-23 08:59:08 +02:00
committed by GitHub
parent a6e736849f
commit 493dd1dc78
2 changed files with 26 additions and 5 deletions

View File

@@ -64,11 +64,18 @@ public class DecimalPropertyEditor : DataEditor
=> TryParsePropertyValue(editorValue.Value);
private static decimal? TryParsePropertyValue(object? value)
=> value is decimal decimalValue
? decimalValue
: decimal.TryParse(value?.ToString(), CultureInfo.InvariantCulture, out var parsedDecimalValue)
? parsedDecimalValue
: null;
=> value switch
{
decimal d => d,
double db => (decimal)db,
float f => (decimal)f,
IFormattable f => decimal.TryParse(f.ToString(null, CultureInfo.InvariantCulture), NumberStyles.Any, CultureInfo.InvariantCulture, out var parsedDecimalValue)
? parsedDecimalValue
: null,
_ => decimal.TryParse(value?.ToString(), CultureInfo.CurrentCulture, out var parsedDecimalValue)
? parsedDecimalValue
: null,
};
/// <summary>
/// Base validator for the decimal property editor validation against data type configured values.