Browse Source

修复小数输入问题

pjzs_starttask_update
sanji 2 years ago
parent
commit
fae8ac5584
  1. 41
      BBWY.Client/Converters/InputNumberConverter.cs
  2. 2
      BBWY.Client/GlobalContext.cs

41
BBWY.Client/Converters/InputNumberConverter.cs

@ -1,4 +1,5 @@
using System;
using MathNet.Numerics;
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
@ -16,14 +17,44 @@ namespace BBWY.Client.Converters
{
string strValue = value as string;
if (string.IsNullOrEmpty(strValue))
{
return null;
}
decimal result;
var dotIndex = strValue.IndexOf('.');
if (dotIndex == strValue.Length - 1 ||
(dotIndex != -1 && strValue.EndsWith("0")) ||
!decimal.TryParse(strValue, out result))
if (strValue.IndexOf('.') == strValue.Length - 1 || (strValue.IndexOf('0') == strValue.Length - 1 && strValue.IndexOf('.') != -1) || !decimal.TryParse(strValue, out result))
{
return DependencyProperty.UnsetValue;
}
return result;
//if (string.IsNullOrEmpty(strValue))
// return DependencyProperty.UnsetValue;
//if (strValue.EndsWith("."))
// return DependencyProperty.UnsetValue;
//decimal result = 0M;
//var dotIndex = strValue.IndexOf('.');
//if (dotIndex == -1)
// decimal.TryParse(strValue, out result);
//else
//{
// //var intValueStr = strValue.Substring(0, dotIndex);
// var decimalValueStr = strValue.Substring(dotIndex + 1);
// var n = 1M;
// if (decimalValueStr.Length == 1)
// n = 1.0M;
// if (decimalValueStr.Length == 2)
// n = 1.00M;
// if (decimalValueStr.Length == 3)
// n = 1.000M;
// if (decimalValueStr.Length == 4)
// n = 1.0000M;
// if (decimal.TryParse(strValue, out result))
// result = decimal.Round(result * n, decimalValueStr.Length);
// else
// return DependencyProperty.UnsetValue;
//}
//return result;
}
}
}

2
BBWY.Client/GlobalContext.cs

@ -13,7 +13,7 @@ namespace BBWY.Client
{
ShopServiceGroupList = new List<string>();
ShopServiceGroupLowerList = new List<string>();
ClientVersion = "10214";
ClientVersion = "10215";
}

Loading…
Cancel
Save