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

Incorrect formatting on very small numbers #19

Open
foundryspatial-duncan opened this issue Aug 17, 2020 · 3 comments
Open

Incorrect formatting on very small numbers #19

foundryspatial-duncan opened this issue Aug 17, 2020 · 3 comments

Comments

@foundryspatial-duncan
Copy link

I found this repo while searching for a fork that fixed the Numeral JS bug "NaN returned if value < 1e-6"
I see that this fork fixes that issue somewhat; it doesn't return NaN anymore, but the formatting of the output string has problems.

If I use format 0,0 on a number like 4.8439166267322474e-8, the formatted string looks like this:

4.8,439,166,267,322,474e-8

Note there are commas in the mantissa after the decimal point. I'd expect an output of 0 here, actually.

Format 0,0.00 returns the same string as above, where I'd expect 0.00 or 4.84e-8 or something.

Here's a codepen that shows the strangeness:
https://codepen.io/foundryspatial-duncan/pen/YzqWxgK

@martinschi
Copy link

martinschi commented Nov 9, 2020

Hello, this is pretty annoying bug and I run into it just now. I have reproduced the same issue with following configuration:

Kibana version: 7.9.2

Elasticsearch version: 7.9.2

Server OS version: Docker

Browser version: Safari 14.0

Browser OS version: Macos 10.15.7

Original install method (e.g. download page, yum, from source, etc.): Docker images
docker.elastic.co/elasticsearch/elasticsearch:7.9.2
docker.elastic.co/kibana/kibana:7.9.2

Reproduction:

Create two documents in test index:

POST test/_doc
{
  "variable": 1.23456e-10
}

POST test/_doc
{
  "variable": 5.6789
}

Create index pattern for this index with default parameters and create table visualization with split rows terms aggregation by variable. You should get something like this:

Screenshot 2020-11-09 at 12 29 29

Change the formatting of variable field in the index pattern to:
0,0.0

Refresh the table visualization to pickup updated format from index pattern. You should see this:

Screenshot 2020-11-09 at 12 31 21

As you can see, bottom number got correctly displayed with single digit behind decimal separator, however the top number hasn't changed, it's still shown as 1.2,345,599,542,662,455e-10, while the expected representation would be 0.0.

@sakurai-youhei
Copy link
Member

sakurai-youhei commented Oct 31, 2022

FYI: v3.0.0 doesn't seem to have the same issue anymore, as it formats small numbers such as 0.0000048439166267322476 well.

https://codepen.io/sakurai-youhei/pen/ExRVpzN

  • format: 0,0.000000000 -> output: 0.000000048
  • format: 0,0.0 -> output: 0.0
  • format: 0,0e+0 -> output: 5e-8
  • format: 0.00e+0 -> 4.84e-8

@eradman
Copy link

eradman commented Jan 26, 2024

I can also confirm that v3.0.0 works

> var numeral = require("@elastic/numeral");
> numeral('1.2e-9').format('0.00000000000')
'0.00000000120'

Will v3.0.0 be tagged as a release soon?

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

No branches or pull requests

4 participants