Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static bool HasDecimalComma;
- public static bool HasDecimalPeriod;
- public static double GetNumber(string NumberString)
- {
- if (!HasDecimalComma && !HasDecimalPeriod)
- {
- string s = string.Format("{0:0.0}", 123.123);
- if (s.Contains('.'))
- {
- HasDecimalPeriod = true;
- }
- else if (s.Contains(','))
- {
- HasDecimalComma = true;
- }
- else
- {
- throw new SystemException(string.Format("strange number format '{0}'", s));
- }
- }
- if (HasDecimalComma)
- {
- return double.Parse(NumberString.Replace('.', ','));
- }
- if (HasDecimalPeriod)
- {
- return double.Parse(NumberString.Replace(',', '.'));
- }
- throw new ArgumentException(string.Format("can't parse '{0}'", NumberString));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement