ant-design-blazor/components/statistic/Statistic.razor.cs
TimChen 3d23cfd5c1 fix(module: pageheader): onback icon (#544)
* feat: fix pageheader onbackicon

* docs: pageheader doc

* docs: pageheader

* fix: anchor _flatLinks is null bug

* fix: custom icon

* fix: custom icon and statictic value converting

Co-authored-by: ElderJames <shunjiey@hotmail.com>
2020-08-31 11:51:11 +08:00

69 lines
2.1 KiB
C#

using System;
using System.Globalization;
using System.Linq;
using Microsoft.AspNetCore.Components;
namespace AntDesign
{
public partial class Statistic<TValue> : StatisticComponentBase<TValue>
{
[Parameter] public string DecimalSeparator { get; set; } = ".";
[Parameter] public string GroupSeparator { get; set; } = ",";
[Parameter] public int Precision { get; set; }
private (string integerPart, string fractionalPart) SeparateDecimal()
{
var decimalValue = 0m;
if (Value is decimal d)
{
decimalValue = d;
}
else if (Value is string value)
{
if (decimal.TryParse(value, out var @decimal))
{
decimalValue = @decimal;
}
else
{
return (value ?? "", "");
}
}
else
{
decimalValue = Convert.ToDecimal(Value, CultureInfo.InvariantCulture);
}
var intValue = (int)decimalValue;
var intString = intValue == 0 ? (decimalValue >= 0 ? "0" : "-0") : intValue.ToString($"###{GroupSeparator}###", CultureInfo.InvariantCulture);
decimalValue = Math.Abs(decimalValue - intValue);
var fractionalPart = "";
if (decimalValue == 0 && Precision > 0)
{
fractionalPart = ".".PadRight(Precision + 1, '0');
}
if (decimalValue != 0)
{
if (Precision <= 0)
{
fractionalPart = decimalValue.ToString(CultureInfo.InvariantCulture);
}
else
{
decimalValue = Math.Round(decimalValue, Precision);
fractionalPart = decimalValue.ToString(CultureInfo.InvariantCulture)
.Replace("0.", DecimalSeparator, true, CultureInfo.InvariantCulture)
.PadRight(Precision + 1, '0');
}
}
return (intString, fractionalPart);
}
}
}