Browse Source

Calculator: localize value

pull/1645/head
brianlagunas_cp 15 years ago
parent
commit
504f833b7e
  1. 10
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/Calculator/Implementation/Calculator.cs
  2. 10
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/Core/Utilities/CalculatorUtilities.cs

10
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/Calculator/Implementation/Calculator.cs

@ -269,7 +269,7 @@ namespace Microsoft.Windows.Controls
private decimal CalculateValue(Operation operation)
{
decimal newValue = decimal.Zero;
decimal currentValue = Decimal.Parse(DisplayText);
decimal currentValue = CalculatorUtilities.ParseDecimal(DisplayText);
switch (operation)
{
@ -345,10 +345,12 @@ namespace Microsoft.Windows.Controls
private void ProcessMemoryKey(Calculator.CalculatorButtonType buttonType)
{
decimal currentValue = CalculatorUtilities.ParseDecimal(DisplayText);
switch (buttonType)
{
case Calculator.CalculatorButtonType.MAdd:
Memory += Decimal.Parse(DisplayText);
Memory += currentValue;
break;
case Calculator.CalculatorButtonType.MC:
Memory = decimal.Zero;
@ -357,10 +359,10 @@ namespace Microsoft.Windows.Controls
DisplayText = Memory.ToString();
break;
case Calculator.CalculatorButtonType.MS:
Memory = Decimal.Parse(DisplayText);
Memory = currentValue;
break;
case Calculator.CalculatorButtonType.MSub:
Memory -= Decimal.Parse(DisplayText);
Memory -= currentValue;
break;
default:
break;

10
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/Core/Utilities/CalculatorUtilities.cs

@ -29,9 +29,12 @@ namespace Microsoft.Windows.Controls.Core.Utilities
case "\b": return Calculator.CalculatorButtonType.Back;
case "\r":
case "=": return Calculator.CalculatorButtonType.Equal;
case ".": return Calculator.CalculatorButtonType.Decimal;
}
//the check for the decimal is not in the switch statement. To help localize we check against the current culture's decimal seperator
if (text == System.Threading.Thread.CurrentThread.CurrentCulture.NumberFormat.CurrencyDecimalSeparator)
return Calculator.CalculatorButtonType.Decimal;
//check for the escape key
if (text == ((char)27).ToString())
return Calculator.CalculatorButtonType.Clear;
@ -193,7 +196,10 @@ namespace Microsoft.Windows.Controls.Core.Utilities
}
}
//TODO: add error handling
public static decimal ParseDecimal(string text)
{
return Decimal.Parse(text, System.Threading.Thread.CurrentThread.CurrentCulture);
}
public static decimal Add(decimal firstNumber, decimal secondNumber)
{

Loading…
Cancel
Save