Skip to content

Formattting of float between -5 and 0 #20564

Closed

Description

@jomar-honsi

Expected behaviour

When using pointFormat with float precision 0 combined with a number between 0 and -0.5 one expects the result be be "0".

Actual behaviour

The string "-0" is displayed. This behaviour has been observed on the Dashboard climate demo, but is a Highcharts issue (see demo).

Live demo with steps to reproduce

https://jsfiddle.net/jomar_honsi/n0gm9r31/25/

  • Hover over December and observe that the tooltip says "-0"

Product version

Highcharts 11.3.0

Affected browser(s)

N.A.

Activity

  1. hubertkozik commented on Feb 1, 2024

    @hubertkozik
    Member

    Hi @jomar-honsi!

    If we do something like this in Chrome browser: parseInt(-0.49999) it gives us the result -0.
    image
    This is the odd JavaScript behavior, but indeed, I think it should be handled in Highcharts.numberFormat function, which now returns the string '-0', like in this demo: https://jsfiddle.net/BlackLabel/9jnfd6s7/ (see console)

    numberFormat function can be fixed with something like this: https://jsfiddle.net/BlackLabel/bdg4rej5/ Fix after comment // --- FIX, then it gives us the 0 without the minus sign.

    Can I ask for your opinion @TorsteinHonsi?

  2. TorsteinHonsi commented on Feb 1, 2024

    @TorsteinHonsi
    Collaborator

    The toFixed method also returns -0 in this case:

    console.log(-0.4999.toFixed(0)); // => -0

    According to Wikipedia, signed zeroes are used in computing. But in practice I agree it looks odd, as our formatted numbers are intended for human interpretation. I'm happy with changing the numberFormat function.

  3. TorsteinHonsi commented on Feb 1, 2024

    @TorsteinHonsi
    Collaborator

    PS: The same Wikipedia article states that

    Informally, one may use the notation "−0" for a negative value that was rounded to zero. This notation may be useful when a negative sign is significant; for example, when tabulating Celsius temperatures, where a negative sign means below freezing.

    But we don't know that at the time of formatting, so unless we want to add another option to the number formats, I think we should just fix it.

  4. self-assigned this
    on May 1, 2024
  5. added a commit that references this issue on May 1, 2024
    b1632a6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions