mirror of
https://github.com/jayfunc/BetterLyrics.git
synced 2026-01-12 10:54:55 +08:00
34 lines
992 B
C#
34 lines
992 B
C#
using Microsoft.UI.Xaml.Data;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
|
|
namespace BetterLyrics.WinUI3.Converter
|
|
{
|
|
public partial class DoubleToDecimalConverter : IValueConverter
|
|
{
|
|
public object Convert(object value, Type targetType, object parameter, string language)
|
|
{
|
|
if (value == null) return string.Empty;
|
|
|
|
if (double.TryParse(value.ToString(), out double number))
|
|
{
|
|
int decimalPlaces = 2;
|
|
if (parameter != null && int.TryParse(parameter.ToString(), out int parsedParams))
|
|
{
|
|
decimalPlaces = parsedParams;
|
|
}
|
|
|
|
return number.ToString($"F{decimalPlaces}");
|
|
}
|
|
|
|
return value.ToString() ?? "";
|
|
}
|
|
|
|
public object ConvertBack(object value, Type targetType, object parameter, string language)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
}
|
|
}
|