Fixed number precision in locations page spool card
This commit is contained in:
@@ -10,6 +10,7 @@ import utc from "dayjs/plugin/utc";
|
||||
import { useEffect, useRef } from "react";
|
||||
import { Link } from "react-router-dom";
|
||||
import SpoolIcon from "../../../components/spoolIcon";
|
||||
import { formatWeight } from "../../../utils/parsing";
|
||||
import { ISpool } from "../../spools/model";
|
||||
import { ItemTypes, SpoolDragItem, useCurrentDraggedSpool } from "../dnd";
|
||||
|
||||
@@ -145,7 +146,7 @@ export function SpoolCard({
|
||||
if (spool.filament.material) str += spool.filament.material + " - ";
|
||||
if (spool.filament.weight) {
|
||||
const remaining_weight = spool.remaining_weight ?? spool.filament.weight;
|
||||
str += `${remaining_weight} / ${spool.filament.weight} g`;
|
||||
str += `${formatWeight(remaining_weight, 0)} / ${formatWeight(spool.filament.weight, 0)}`;
|
||||
}
|
||||
if (spool.last_used) {
|
||||
// Format like "last used X time ago"
|
||||
|
||||
@@ -97,7 +97,8 @@ export function formatWeight(weightInGrams: number, precision: number = 2): stri
|
||||
const kilograms = (weightInGrams / 1000).toFixed(precision).replace(/\.?0+$/, ""); // Remove trailing zeros
|
||||
return `${kilograms} kg`;
|
||||
} else {
|
||||
return `${weightInGrams} g`;
|
||||
const grams = weightInGrams.toFixed(precision).replace(/\.?0+$/, ""); // Remove trailing zeros
|
||||
return `${grams} g`;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user