diff --git a/src/components/nested-table.tsx b/src/components/nested-table.tsx index 9efd6ed..bd963fc 100644 --- a/src/components/nested-table.tsx +++ b/src/components/nested-table.tsx @@ -112,10 +112,18 @@ export const NestedTable = (props: IProps) => { precisions: Record, attrTypes: Record, isParent?: boolean, resizeCounter?: number, parentLevel?: number) => { return Object.keys(values).map((key, index) => { - const val = attrTypes[key] === "numeric" ? parseFloat(values[key]) : values[key]; + const isWholeNumber = values[key] % 1 === 0; + const precision = precisions[key] || 2; // default to 2 decimal places + // Numbers are sometimes passed in from CODAP as a string so we use the attribute type to + // determine if it should be parsed as a number. + // Numbers that are whole numbers are treated as integers, so we should ignore the precision. + // Numeric cells that are empty should be treated as empty strings. + const val = attrTypes[key] !== "numeric" || (attrTypes[key] === "numeric" && values[key] === "") + ? values[key] + : attrTypes[key] === "numeric" && !isWholeNumber + ? (parseFloat(values[key])).toFixed(precision) + : parseInt(values[key],10); if (typeof val === "string" || typeof val === "number") { - if (typeof val === "number") { - const precision = precisions[key] || 2; // default to 2 decimal places return ( { resizeCounter={resizeCounter} parentLevel={parentLevel} > - {val.toFixed(precision)} + {val} ); - } - return ( - - {val} - - ); } }); };