fix: correctly format weight and kg columns to 2 decimals

This commit is contained in:
Christian Vidal Wolf
2026-03-29 14:55:30 +02:00
parent 912fb16cb0
commit 27a161bfbb
2 changed files with 22 additions and 24 deletions
+8 -9
View File
@@ -22,16 +22,15 @@ export function MatrixView({ data, headers }: MatrixViewProps) {
const h = header.toLowerCase();
// Do NOT format columns that are clearly IDs, barcodes, or codes
if (h.includes('id') || h.includes('no') || h.includes('code') || h.includes('art.') || h.includes('barcode') || h.includes('article')) {
// But allow if it's a weight/measure column (e.g. Article NW (kg))
if ((h.includes('id') || h.includes('no') || h.includes('code') || h.includes('art.') || h.includes('barcode') || h.includes('article')) &&
!(h.includes('nw') || h.includes('gw') || h.includes('weight') || h.includes('kg'))) {
return val;
}
// List of keywords that typically indicate a price or numeric value to format
const priceKeywords = ['price', 'eur', 'cost', 'msrp', 'net', 'gross', 'netto', 'brutto', 'pp', 'pph', 'uvp', 'vpe', 'stk'];
const isPriceCol = priceKeywords.some(kw => h.includes(kw));
// Format weight columns (NW = Net Weight, GW = Gross Weight, kg, etc.)
const isWeightCol = h.includes('nw') || h.includes('gw') || h.includes('weight') || h.includes('kg');
// List of keywords that typically indicate a price, measure or numeric value to format
const formatKeywords = ['price', 'eur', 'cost', 'msrp', 'net', 'gross', 'netto', 'brutto', 'pp', 'pph', 'uvp', 'vpe', 'stk', 'nw', 'gw', 'weight', 'kg'];
const shouldFormat = formatKeywords.some(kw => h.includes(kw));
// Handle numbers
if (typeof val === 'number') {
@@ -45,8 +44,8 @@ export function MatrixView({ data, headers }: MatrixViewProps) {
const num = parseFloat(normalized);
if (!isNaN(num)) {
// Format if it's a price column, weight column, OR if it already has a decimal separator (.)
if (isPriceCol || isWeightCol || val.includes('.') || val.includes(',')) {
// Format if header contains keywords OR if it already looks like a decimal
if (shouldFormat || val.includes('.') || val.includes(',')) {
return num.toFixed(2);
}
}