Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

numberFilter unnecessary string to number to string conversion => precision issue #16175

Open
@msperisen

Description

@msperisen

I'm submitting a ...

  • bug report
  • feature request
  • other (Please do not submit support requests here (see above))

Current behavior:
'9999999999999999' | number:0 => 10,000,000,000,000,000
9999999999999999 | number:0 => 10,000,000,000,000,000

Expected / new behavior:
'9999999999999999' | number:0 => 9,999,999,999,999,999
9999999999999999 | number:0 => 10,000,000,000,000,000

Minimal reproduction of the problem with instructions:
see plnkr

AngularJS version:
all

Browser:
all
Anything else:
the problem stems from an - in my opinion - unnecessary conversion from string to number to string in the formatNumber function. basically just to remove the sign from the string with Math.abs().
doing something like the snipped below would allow to correctly format string number presentation - without limits of number precision (up to the limits defined by the rest of the code).
in some cases this is enough and one does not have to go for a big(int|number) implementation with corresponding localised formatters.

var numStr =  isString(number) ? (number.startsWith('-') || number.startsWith('+') ? number.substring(1): number) : Math.abs(number) + ''

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions