This is done to avoid decimal parsing issues when applications set a non-US culture that use a different decimal separator (such as it-IT).
Bug info
I reproduced this bug on Blazor WASM, this has been present for a long time (Blazor-ApexCharts v1.x).
If the application sets the current culture to a culture that does not use the dot . as the decimal separator, then the decimal passed to the FormatYAxisLabel callback has all the decimals removed. Ex. the value 1.23 becomes 123.
I fixed it by not relying on decimal.Parse but on the JsonElement.TryGetDecimal method, that works correctly regardless of the current culture.
@code
{
public record TestItem(string Id, decimal? Value);
public TestItem[] Items => new[]
{
new TestItem("1", 1.0m),
new TestItem("2", 2.123m),
new TestItem("3", 3.123m),
new TestItem("4", null),
new TestItem("5", 5.123m),
};
private string MyFormatYAxisLabel(decimal arg)
{
return arg.ToString("c"); // should format to euros
}
This is done to avoid decimal parsing issues when applications set a non-US culture that use a different decimal separator (such as it-IT).
Bug info
I reproduced this bug on Blazor WASM, this has been present for a long time (Blazor-ApexCharts v1.x). If the application sets the current culture to a culture that does not use the dot . as the decimal separator, then the decimal passed to the FormatYAxisLabel callback has all the decimals removed. Ex. the value 1.23 becomes 123.
I fixed it by not relying on decimal.Parse but on the JsonElement.TryGetDecimal method, that works correctly regardless of the current culture.
Steps to reproduce:
Set the current culture to
it-IT
.Create a chart with FormatYAxisLabel set. Full example:
@code { public record TestItem(string Id, decimal? Value);
}