Browse Source

numeric updown controls: fixed the percent formatting

pull/1645/head
brianlagunas_cp 15 years ago
parent
commit
bbb53816ce
  1. 2
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/NumericUpDown/Implementation/DecimalUpDown.cs
  2. 2
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/NumericUpDown/Implementation/DoubleUpDown.cs
  3. 3
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/NumericUpDown/Implementation/IntegerUpDown.cs
  4. 29
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/NumericUpDown/Implementation/NumericUpDown.cs

2
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/NumericUpDown/Implementation/DecimalUpDown.cs

@ -55,7 +55,7 @@ namespace Microsoft.Windows.Controls
try
{
result = Decimal.Parse(text, System.Globalization.NumberStyles.Any, CultureInfo);
result = FormatString.Contains("P") ? ParsePercent(text, CultureInfo) : ParseDecimal(text, CultureInfo);
}
catch
{

2
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/NumericUpDown/Implementation/DoubleUpDown.cs

@ -55,7 +55,7 @@ namespace Microsoft.Windows.Controls
try
{
result = Double.Parse(text, System.Globalization.NumberStyles.Any, CultureInfo);
result = FormatString.Contains("P") ? Decimal.ToDouble(ParsePercent(text, CultureInfo)) : ParseDouble(text, CultureInfo);
}
catch
{

3
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/NumericUpDown/Implementation/IntegerUpDown.cs

@ -55,7 +55,8 @@ namespace Microsoft.Windows.Controls
try
{
result = Int32.Parse(text, System.Globalization.NumberStyles.Any, CultureInfo);
//don't know why someone would format an integer as %, but just in case they do.
result = FormatString.Contains("P") ? Decimal.ToInt32(ParsePercent(text, CultureInfo)) : ParseInt(text, CultureInfo);
}
catch
{

29
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/NumericUpDown/Implementation/NumericUpDown.cs

@ -2,6 +2,7 @@
using System.Windows;
using System.Windows.Input;
using Microsoft.Windows.Controls.Primitives;
using System.Globalization;
namespace Microsoft.Windows.Controls
{
@ -156,6 +157,34 @@ namespace Microsoft.Windows.Controls
// Spinner.ValidSpinDirection = validDirections;
//}
protected static decimal ParseDecimal(string text, IFormatProvider cultureInfo)
{
return Decimal.Parse(text, NumberStyles.Any, cultureInfo);
}
protected static double ParseDouble(string text, IFormatProvider cultureInfo)
{
return Double.Parse(text, NumberStyles.Any, cultureInfo);
}
protected static int ParseInt(string text, IFormatProvider cultureInfo)
{
return Int32.Parse(text, NumberStyles.Any, cultureInfo);
}
protected static decimal ParsePercent(string text, IFormatProvider cultureInfo)
{
NumberFormatInfo info = NumberFormatInfo.GetInstance(cultureInfo);
text = text.Replace(info.PercentSymbol, null);
decimal result = Decimal.Parse(text, NumberStyles.Any, info);
result = result / 100;
return result;
}
#endregion //Methods
}
}

Loading…
Cancel
Save