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

Improve readability of SI format for very small/large numbers #111

Open
patkwee opened this issue Mar 27, 2021 · 2 comments
Open

Improve readability of SI format for very small/large numbers #111

patkwee opened this issue Mar 27, 2021 · 2 comments

Comments

@patkwee
Copy link

patkwee commented Mar 27, 2021

It would be great to improve the 'human-readability' of SI format "s" for very small/large numbers. At the moment d3-format generates:

console.log(format("s")(1e-50))  -> "0.00000000000000000000000001y"
console.log(format("s")(1e+50)) -> "100000000000000000000000000Y"

I would propose to fall back to exponent notation ("e" format) for numbers below abs(x)<1e-24 or above abs(x)>1e24.

In my application, usually the numbers are in a range where the "s"-format makes sense. Though, sometimes, e.g. due to numerical inaccuracy of calculations, I get very small numbers, that blow-up my output.

@Fil
Copy link
Member

Fil commented Mar 27, 2021

For small numbers you could round the number before formatting:

a => format("s")(+a.toFixed(26));

@patkwee
Copy link
Author

patkwee commented Mar 28, 2021

Yes, true. I currently just check for abs(x)<1e-24 and then use "e" or "s" formatting. My point is more that a 'human' would format 1e-50 rather as 1e-50 than as 0.00000000000000000000000001y and therefore it might be an interesting improvement proposal.

Libraries like vega and vega-lite also use d3-format. There a workaround is also possible with custom formatters, but it gets more and more tedious.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants