Ooui-tws-port/Samples/TipCalc/DoubleToStringConverter.cs

33 lines
862 B
C#
Raw Normal View History

2017-12-12 20:25:56 +00:00
using System;
using System.Globalization;
using Xamarin.Forms;
namespace TipCalc
{
public class DoubleToStringConverter : IValueConverter
{
public object Convert(object value, Type targetType,
object parameter, CultureInfo culture)
{
// Assumes value is double.
double number = (double)value;
// Return empty string for a zero (good for Entry views).
if (number == 0)
{
return "";
}
return number.ToString();
}
public object ConvertBack(object value, Type targetType,
object parameter, CultureInfo culture)
{
double number = 0;
Double.TryParse((string)value, out number);
return number;
}
}
}