Procházet zdrojové kódy

Improve FormatFloat parsing

Tatiana Inama před 6 roky
rodič
revize
e9848d90a7
1 změnil soubory, kde provedl 4 přidání a 2 odebrání
  1. 4 2
      recipes/src/services/measurements.ts

+ 4 - 2
recipes/src/services/measurements.ts

@@ -78,9 +78,11 @@ const ParseUnit = (unit: string): Measure => {
 }
 
 const FormatFloat = (n: number) => {
-  const _n = n.toFixed(2);
+  const _n = n.toFixed(1);
   const [ integer, decimal ] = _n.split('.');
-  return decimal === '00' ? parseFloat(integer) : parseFloat(_n);
+  //     do not show .00 decimals or decimals for numbers greater than 100 => negligible
+  return decimal === '00' || integer.length >= 3 ? 
+          parseFloat(integer) : parseFloat(_n);
 }
 
 const MeasuresTypes = GetMeasuresTypes();