Files
DP44/Common/DTS.CommonCore/Converters/DoubleFromThousandthUnitToBaseUnit.cs
2026-04-17 14:55:32 -04:00

48 lines
1.4 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
namespace DTS.Common.Converters
{
public class DoubleFromThousandthUnitToBaseUnit : IValueConverter
{
/// <summary>
/// Used to convert a Thousandth value to its base unit.
/// For example to convert millivolts to volts
/// </summary>
/// <param name="value"></param>
/// <param name="targetType"></param>
/// <param name="parameter"></param>
/// <param name="culture"></param>
/// <returns></returns>
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value is double milliUnit)
{
if (double.IsNaN(milliUnit)) { return 0D; }
return milliUnit / 1000.0D;
}
else
{
return 0D;
}
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value is double unit)
{
if (double.IsNaN(unit)) { return 0D; }
return unit * 1000.0D;
}
else
{
return 0D;
}
}
}
}