Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[187242185] Mirror CODAP precision on numbers. #35

Merged
merged 2 commits into from
Apr 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions src/components/nested-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,23 @@ export const NestedTable = (props: IProps) => {
// 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] !== null)
|| (values[key] === "")
|| (typeof values[key] !== "number")
? values[key]
: isWholeNumber
? parseInt(values[key],10)
: precision !== undefined
? (parseFloat(values[key])).toFixed(precision)
: (parseFloat(values[key])).toFixed(2); // default to 2 decimal places
const isNumericType = attrTypes[key] === "numeric";
const hasValue = values[key] !== "";
const parsedValue = parseFloat(values[key]);
const isNumber = !isNaN(parsedValue);
const hasPrecision = precision !== undefined;
const defaultValue = values[key];
const isNumberType = typeof values[key] === "number";
let val;
if (isNumericType && hasValue && isNumber) {
val = isWholeNumber ? parseInt(values[key], 10)
: parsedValue.toFixed(hasPrecision ? precision : 2);
} else if (!isNumericType && isNumberType && hasValue) {
val = defaultValue.toFixed(hasPrecision ? precision : 2);
} else {
val = defaultValue;
}

if (attrVisibilities[key]) {
return null;
}
Expand Down
Loading