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

RN-832: Raw data exports treat numbers as text #4424

Merged
merged 2 commits into from
Apr 17, 2023

Conversation

chris-pollard
Copy link
Contributor

Issue RN-832:

Changes:

  • Add 'number' check in the useTableExport hook function.

? tableData.map(row =>
tableColumns.map(col => {
const value = row.values[col.id];
return isNaN(value) ? value : Number(value);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isNaN() has a surprising behaviour. The logic provided here will convert empty string '', false, null..etc to 0 because isNaN use Number() to validate the type and Number(false) = 0, so isNaN(false) = false..

Here I suggest we can do something like:

function convertToNumber(str) {
  // Try to parse the string as a floating-point number
  const num = parseFloat(str);

  // Check if the parsed value is a number (not NaN)
  if (!isNaN(num)) {
    return num;
  }

  // If the parsed value is NaN, return the original string
  return str;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, @biaoli0 , thanks for the suggestion

@chris-pollard chris-pollard merged commit 71d6174 into dev Apr 17, 2023
@chris-pollard chris-pollard deleted the rn-832-num-excel-dwnld branch April 17, 2023 04:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants