[chronojump/michrolab] At Util better code for overloaded ConvertToPoint and GetSpeed



commit f89872ad6031ea1c1bc9aad7fe8865f77a6aadfc
Author: Xavier de Blas <xaviblas gmail com>
Date:   Wed Aug 31 14:04:55 2022 +0200

    At Util better code for overloaded ConvertToPoint and GetSpeed

 src/util.cs | 22 +++++++++-------------
 1 file changed, 9 insertions(+), 13 deletions(-)
---
diff --git a/src/util.cs b/src/util.cs
index 1830bf1e4..77123fb35 100644
--- a/src/util.cs
+++ b/src/util.cs
@@ -82,13 +82,9 @@ public class Util
        //all numbers are saved in database with '.' as decimal separator (method for numbers)
        public static string ConvertToPoint (double myDouble)
        {
-               StringBuilder myStringBuilder = new StringBuilder(myDouble.ToString());
-               myStringBuilder.Replace(",", ".");
-               return myStringBuilder.ToString();
+               return ConvertToPoint (myDouble.ToString ());
        }
-       
        //all numbers are saved in database with '.' as decimal separator
-       //method for the tvString, tcString, and runIntervalTimesString
        public static string ConvertToPoint (string myString)
        {
                StringBuilder myStringBuilder = new StringBuilder(myString);
@@ -738,17 +734,17 @@ public class Util
        }
 
 
-       //public static string GetSpeed (string distance, string time) {
-       public static string GetSpeed (string distance, string time, bool metersSecondsPreferred) {
-               double distanceAsDouble = Convert.ToDouble(distance);
-               double timeAsDouble = Convert.ToDouble(time);
-
+       public static string GetSpeed (string distance, string time, bool metersSecondsPreferred)
+       {
+               return GetSpeed (Convert.ToDouble (distance), Convert.ToDouble (time), 
metersSecondsPreferred).ToString ();
+       }
+       public static double GetSpeed (double distance, double time, bool metersSecondsPreferred)
+       {
                if(metersSecondsPreferred)
-                       return (distanceAsDouble / timeAsDouble).ToString();
+                       return UtilAll.DivideSafe (distance, time);
                else
-                       return (3.6 * distanceAsDouble / timeAsDouble).ToString();
+                       return UtilAll.DivideSafe (3.6 * distance, time);
        }
-                                       
        
        public static int FetchID (string text)
        {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]