Skip to content

A way to get the nearest SI magnitude #3

@C-Duv

Description

@C-Duv

In both Number::getSuffixNotation() and MagnitudeSuffix::__toString(), the nearest SI magnitude is computed using:

3 * floor($magnitude/3)

It would be convenient if either Number or MagnitudeSuffix could provide such information.

In my case I am using PHP's round() with negative precision parameter to round a given number to k, M, G, etc. without any decimal part:

$suffixed = Number::n(
        round(
            $input_number,
            -1 * (3 * floor(Number::n($input_number)->getMagnitude()/3))
        )
    )
    ->getSuffixNotation();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions