Advertisement
tranerius

value_check C#

Feb 27th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.81 KB | None | 0 0
  1. public static double Value_check()
  2. {
  3.     bool was_point = false;
  4.     string check = System.Console.ReadLine();
  5.     for (int i = 0; i < check.Length; i++)
  6.     {
  7.         if (check[i] == '.' || check[i] == ',' && !was_point)
  8.         {
  9.             check = check.Remove(i, 1);
  10.             check = check.Insert(i, ",");
  11.             was_point = true;
  12.         }
  13.         else if (check[i] == '.' || check[i] == ',' && was_point)
  14.         {
  15.             check = check.Remove(i, 1);
  16.             i--;
  17.         }
  18.         if ((check[i] < 48 && check[i] != 43 && check[i] != 44 && check[i] != 45 && check[i] != 0) || check[i] > 57)
  19.         {
  20.             check = check.Remove(i, 1);
  21.             i--;
  22.         }
  23.     }
  24.     if (check.Length == 0)
  25.     {
  26.         return 0;
  27.     }
  28.     return System.Convert.ToDouble(check);
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement