Skip to content

Rounding with significant digits precision gives wrong results #821

@shivijais

Description

@shivijais
Globalize.numberFormatter({
        compact: 'short',
        minimumSignificantDigits: 1,
        maximumSignificantDigits: 3,
    })(12849872883)

Actual => 12.9B
Expected => 12.8B

Root cause for this is in the method numberToPrecision which first changes the precision from actual precision to a +2. and then rounds the number based on the given precision. So the number in this case 12849872883 changes to 12.850 and when finally rounded becomes 12.9

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions