Intl.Collator and natural sort with a numeric parameter are not sorted correctly with decimal numbers

Sort decimal numbers with Intl.Collator, and the enable option numericincorrectly compares decimals.

In some browsers comparing β€œ0.005” and β€œ0.05”, β€œ0” is returned, since the numbers are the same.

Results in different browsers:

  • Chrome 54 = 0
  • Firefox 49 = 0
  • Edge = -1
  • IE 11 = -1

// Returns 0
console.log(new Intl.Collator(undefined, { numeric: true}).compare(0.000005, 0.05))
Run codeHide result

Anyone who can tell me what's wrong?

Report a bug in Firefox: https://bugzilla.mozilla.org/show_bug.cgi?id=1312388

+3
source share
1 answer

Firefox, , Unicode Number, . , , , U + 002E FULL STOP Number ( ).

, - "0,05" "0,000005" - :

["0", ".", "05"]
["0", ".", "000005"]

, ,

[0, ".", 5]
[0, ".", 5]

, compare 0 . Firefox Chrome , IE Edge .

+1

Source: https://habr.com/ru/post/1658083/


All Articles