Files
ShrlAlgoToolkit/WPFluent/Converters/MathRoundConverter.cs

25 lines
622 B
C#
Raw Normal View History

2024-09-22 11:05:41 +08:00
using System;
using System.Linq;
using System.Windows.Data;
namespace WPFluent.Converters;
2025-04-24 20:56:44 +08:00
internal class MathRoundConverter : IValueConverter
2024-09-22 11:05:41 +08:00
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var d = (double)value;
return Math.Round(d, MidpointRounding.AwayFromZero);
2024-09-22 11:05:41 +08:00
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
var str = value.ToString();
2025-04-24 20:56:44 +08:00
if (double.TryParse(str, out var d))
2024-09-22 11:05:41 +08:00
{
return d;
}
return Binding.DoNothing;
}
}