Skip to content

fix(charts): fix engineering notation formatter locale issue

Tristan Read requested to merge tr-remove-unused-formatting-code into master

This MR tidies up the engineeringNotation function, in accordance with the proposed fix on this bug ticket: #717 (closed)

Changes:

  • No longer use special parsing for strings containing digit grouping characters, as this was not locale-aware and could cause unexpected behaviour.
  • Add a specification to cover the case where a number-parseable string is passed as an input.
  • More closely follow the behaviour of Intl.NumberFormat.prototype.format():
    • Parse string inputs according to Number(string) rather than parseFloat(string)
    • Return "NaN" when string is unparseable

Note: A scan of the @gitlab-ui and gitlab-org/gitlab codebases shows that we never call this function with a string as an input, so we should be ok to change the behaviour.

Related MR: !1222 (merged)

Edited by Tristan Read

Merge request reports