ant-design-blazor/components/statistic/Statistic.razor.cs
TimChen 6e74917b43 feat: add page-header component (#211)
* feat: add page-header components

* feat: add page-header components

* feat: add page-header components

* docs: some bugs of PageHeader

* refactor: clean code

Co-authored-by: ElderJames <shunjiey@hotmail.com>
2020-06-13 00:47:00 +08:00

49 lines
1.6 KiB
C#

using System;
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; } = -1;
private string IntegerPart
{
get
{
if (typeof(TValue).IsAssignableFrom(typeof(string))) return Value.ToString();
else return Convert.ToDecimal(Value).ToString($"###{GroupSeparator}###");
}
}
private string FractionalPart
{
get
{
if (typeof(TValue).IsAssignableFrom(typeof(string)))
{
return null;
}
else
{
string tem;
if (Precision > 0)
tem = Math.Round(Convert.ToDecimal(Value), Precision).ToString().Contains('.')
? Math.Round(Convert.ToDecimal(Value), Precision).ToString().Split('.').Last().PadRight(Precision, '0')
: string.Empty.PadRight(Precision, '0');
else if (Precision < 0)
tem = Value.ToString().Contains('.') ? Value.ToString().Split('.').Last() : null;
else
tem = null;
return string.IsNullOrEmpty(tem) ? null : DecimalSeparator + tem;
}
}
}
}
}