19319: Add container / workflow cost details
[arvados-workbench2.git] / src / common / formatters.ts
index 6d0a7e491e4e508384ccbad42f66cc2eb3f8c195..b16465127e96835ae8ac994fd080f1b878883461 100644 (file)
@@ -99,3 +99,17 @@ export const formatPropertyValue = (pv: PropertyValue, vocabulary?: Vocabulary)
     }
     return "";
 };
+
+export const formatContainerCost = (cost: number) => {
+    const decimalPlaces = 3;
+
+    const factor = Math.pow(10, decimalPlaces);
+    const rounded = Math.round(cost*factor)/factor;
+    if (cost > 0 && rounded === 0) {
+        // Display min value of 0.001
+        return `$${1/factor}`;
+    } else {
+        // Otherwise use rounded value to proper decimal places
+        return `$${rounded}`;
+    }
+};