Format numbers fix
This commit is contained in:
50
DiunaBI.UI.Shared/Services/NumberFormatHelper.cs
Normal file
50
DiunaBI.UI.Shared/Services/NumberFormatHelper.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using System.Globalization;
|
||||
|
||||
namespace DiunaBI.UI.Shared.Services;
|
||||
|
||||
public class NumberFormatHelper
|
||||
{
|
||||
private readonly CultureInfo _culture;
|
||||
|
||||
public NumberFormatHelper()
|
||||
{
|
||||
// Always use Polish culture for number formatting
|
||||
_culture = CultureInfo.GetCultureInfo("pl-PL");
|
||||
}
|
||||
|
||||
public string FormatNumber(double? value, int decimals = 2)
|
||||
{
|
||||
if (!value.HasValue)
|
||||
return string.Empty;
|
||||
|
||||
return value.Value.ToString($"N{decimals}", _culture);
|
||||
}
|
||||
|
||||
public string FormatNumber(double value, int decimals = 2)
|
||||
{
|
||||
return value.ToString($"N{decimals}", _culture);
|
||||
}
|
||||
|
||||
public string FormatInteger(double? value)
|
||||
{
|
||||
if (!value.HasValue)
|
||||
return string.Empty;
|
||||
|
||||
return value.Value.ToString("N0", _culture);
|
||||
}
|
||||
|
||||
public string FormatInteger(double value)
|
||||
{
|
||||
return value.ToString("N0", _culture);
|
||||
}
|
||||
|
||||
public string GetCultureName()
|
||||
{
|
||||
return _culture.DisplayName;
|
||||
}
|
||||
|
||||
public CultureInfo GetCulture()
|
||||
{
|
||||
return _culture;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user