Parcourir la source

фикс точки

Rimmon il y a 2 ans
Parent
commit
8c4f2a381f
1 fichiers modifiés avec 29 ajouts et 9 suppressions
  1. 29 9
      Pages/ModalAssets.razor

+ 29 - 9
Pages/ModalAssets.razor

@@ -106,8 +106,10 @@
     bool counter = false;
     void cfi(string val)
     {
-        counter = true;
-        fromInput = val.ToString();
+        if (!counter)
+            fi = val;
+        else
+            counter = false;
     }
 
     string fromInput
@@ -115,15 +117,24 @@
         get { return fi;
         }
         set { fi = value;
-            if (!counter)
+
+            try
             {
                 var val = float.Parse(fi, System.Globalization.CultureInfo.InvariantCulture);
                 //var val = System.Convert.ToSingle(fi);
-                val *= 5;
+                val *= 5f;
+                var last = value[value.Length - 1];
+                if (last == '.' || last == ',')
+                {
+                    counter = true;
+                }
                 toInput = val.ToString();
             }
-            else
-                counter = false;
+            catch (Exception e)
+            {
+                toInput = "0";
+                Console.WriteLine(e.Message);
+            }
         }
     }
 
@@ -131,9 +142,18 @@
     {
         get { return ti; }
         set { ti = value;
-            var val = System.Convert.ToSingle(ti);
-            val /= 5;
-            cfi(val.ToString());    //prevent overflow
+
+            try
+            {
+                var val = float.Parse(ti, System.Globalization.CultureInfo.InvariantCulture);
+                val /= 5f;
+                cfi(val.ToString());    //prevent overflow
+            }
+            catch (Exception e)
+            {
+                fromInput = "0";
+                Console.WriteLine(e.Message);
+            }
         }
     }
     string ft;