diff --git a/app/pages/system/UtilizationPage.tsx b/app/pages/system/UtilizationPage.tsx
index 4fed415e46..5acbf76d2a 100644
--- a/app/pages/system/UtilizationPage.tsx
+++ b/app/pages/system/UtilizationPage.tsx
@@ -24,7 +24,7 @@ import {
Table,
Tabs,
} from '@oxide/ui'
-import { bytesToGiB, bytesToTiB } from '@oxide/util'
+import { bytesToGiB, bytesToTiB, round } from '@oxide/util'
import { CapacityBars } from 'app/components/CapacityBars'
import { useDateTimeRangePicker } from 'app/components/form'
@@ -254,7 +254,8 @@ const AvailableCell = ({
return (
- {allocated - provisioned} {unit && {unit}}
+ {round(allocated - provisioned, 2)}
+ {unit && {unit}}
{/* We only show the ResourceMeter if the percent crosses the warning threshold (66%) */}
{usagePercent > 66 && (
diff --git a/app/test/e2e/utilization.e2e.ts b/app/test/e2e/utilization.e2e.ts
index fbe2201887..72eaff7984 100644
--- a/app/test/e2e/utilization.e2e.ts
+++ b/app/test/e2e/utilization.e2e.ts
@@ -21,13 +21,13 @@ test.describe('System utilization', () => {
const table = page.getByRole('table')
await expectRowVisible(table, {
- CPU: '20 ',
+ CPU: '20',
Storage: '2.7 TiB',
Memory: '66 GiB',
Silo: 'maze-war',
})
await expectRowVisible(table, {
- CPU: '26 ',
+ CPU: '26',
Storage: '7 TiB',
Memory: '350 GiB',
Silo: 'myriad',
diff --git a/libs/util/math.spec.ts b/libs/util/math.spec.ts
index 19c6f2b4d0..cca1f9b865 100644
--- a/libs/util/math.spec.ts
+++ b/libs/util/math.spec.ts
@@ -16,6 +16,7 @@ it('rounds properly', () => {
expect(round(123.456, 2)).toEqual(123.46)
expect(round(123.456, 3)).toEqual(123.456)
expect(round(123.456, 4)).toEqual(123.456) // trailing zeros are culled
+ expect(round(123.0001, 3)).toEqual(123) // period is culled if decimals are all zeros
expect(round(1.9, 0)).toEqual(2)
expect(round(1.9, 1)).toEqual(1.9)
expect(round(5 / 2, 2)).toEqual(2.5) // math expressions are resolved
diff --git a/libs/util/math.ts b/libs/util/math.ts
index dc65df8619..4b36a4b2e9 100644
--- a/libs/util/math.ts
+++ b/libs/util/math.ts
@@ -16,6 +16,5 @@ export function splitDecimal(value: number) {
}
export function round(num: number, digits: number) {
- const pow10 = Math.pow(10, digits)
- return Math.round((num + Number.EPSILON) * pow10) / pow10
+ return Number(num.toFixed(digits))
}