Format numbers fix
This commit is contained in:
@@ -45,6 +45,7 @@ public static class ServiceCollectionExtensions
|
|||||||
services.AddScoped<DataInboxService>();
|
services.AddScoped<DataInboxService>();
|
||||||
services.AddScoped<JobService>();
|
services.AddScoped<JobService>();
|
||||||
services.AddScoped<DateTimeHelper>();
|
services.AddScoped<DateTimeHelper>();
|
||||||
|
services.AddScoped<NumberFormatHelper>();
|
||||||
|
|
||||||
// Filter state services (scoped to maintain state during user session)
|
// Filter state services (scoped to maintain state during user session)
|
||||||
services.AddScoped<LayerFilterStateService>();
|
services.AddScoped<LayerFilterStateService>();
|
||||||
|
|||||||
@@ -165,12 +165,12 @@
|
|||||||
<FooterContent>
|
<FooterContent>
|
||||||
@if (showSummary)
|
@if (showSummary)
|
||||||
{
|
{
|
||||||
<MudTd><b>@totalSum.ToString("N2")</b></MudTd>
|
<MudTd><b>@NumberFormatHelper.FormatNumber(totalSum)</b></MudTd>
|
||||||
@foreach (var column in displayedColumns)
|
@foreach (var column in displayedColumns)
|
||||||
{
|
{
|
||||||
@if (column.StartsWith("Value") && columnSums.ContainsKey(column))
|
@if (column.StartsWith("Value") && columnSums.ContainsKey(column))
|
||||||
{
|
{
|
||||||
<MudTd><b>@columnSums[column].ToString("N2")</b></MudTd>
|
<MudTd><b>@NumberFormatHelper.FormatNumber(columnSums[column])</b></MudTd>
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -32,6 +32,9 @@ public partial class Details : ComponentBase, IDisposable
|
|||||||
[Inject]
|
[Inject]
|
||||||
private DateTimeHelper DateTimeHelper { get; set; } = null!;
|
private DateTimeHelper DateTimeHelper { get; set; } = null!;
|
||||||
|
|
||||||
|
[Inject]
|
||||||
|
private NumberFormatHelper NumberFormatHelper { get; set; } = null!;
|
||||||
|
|
||||||
private LayerDto? layer;
|
private LayerDto? layer;
|
||||||
private List<RecordDto> records = new();
|
private List<RecordDto> records = new();
|
||||||
private List<string> displayedColumns = new();
|
private List<string> displayedColumns = new();
|
||||||
@@ -191,7 +194,7 @@ public partial class Details : ComponentBase, IDisposable
|
|||||||
}
|
}
|
||||||
|
|
||||||
var value = GetRecordValueByName(record, columnName);
|
var value = GetRecordValueByName(record, columnName);
|
||||||
return value.HasValue ? value.Value.ToString("N2") : string.Empty;
|
return NumberFormatHelper.FormatNumber(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
private double? GetRecordValueByName(RecordDto record, string columnName)
|
private double? GetRecordValueByName(RecordDto record, string columnName)
|
||||||
|
|||||||
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