瀏覽代碼

Improve FormatFloat parsing

Tatiana Inama 6 年之前
父節點
當前提交
e9848d90a7
共有 1 個文件被更改,包括 4 次插入2 次删除
  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();