51 lines
1.7 KiB
C#
51 lines
1.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Globalization;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Data;
|
|
|
|
namespace DTS.Common.Converters
|
|
{
|
|
public class NumericStringFormatConverter : IMultiValueConverter
|
|
{
|
|
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
if (null != values && values.Length == 2)
|
|
{
|
|
try
|
|
{
|
|
if (values[0] is int i)
|
|
{
|
|
return i.ToString(values[1] as string, CultureInfo.InvariantCulture);
|
|
}
|
|
if (values[0] is double d)
|
|
{
|
|
return (d is double.NaN) ? Strings.Strings.Table_NA : d.ToString(values[1] as string, CultureInfo.InvariantCulture);
|
|
}
|
|
if (values[0] is float f)
|
|
{
|
|
return (f is float.NaN) ? Strings.Strings.Table_NA : f.ToString(values[1] as string, CultureInfo.InvariantCulture);
|
|
}
|
|
if (values[0] is decimal deci)
|
|
{
|
|
return deci.ToString(values[1] as string, CultureInfo.InvariantCulture);
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
}
|
|
}
|