using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Data;
namespace XAMLFinance.View.Converter
{
public class VolumeToStringConverter : IValueConverter
{
private const double Million = 1000000;
private const double Billion = 1000000000;
private const double Trillion = 1000000000000;
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
double? doubleValue = value as double?;
if (!doubleValue.HasValue)
return null;
double volume = doubleValue.Value;
if (volume < Million)
{
return string.Format("{0}", volume);
}
else if (volume < Billion)
{
return string.Format("{0:N2} M", volume / Million);
}
else if (volume < Trillion)
{
return string.Format("{0:N2} B", volume / Billion);
}
else
{
return string.Format("{0:N2} T", volume / Trillion);
}
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
}