Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A way to get the nearest SI magnitude #3

Open
C-Duv opened this issue Feb 21, 2017 · 0 comments
Open

A way to get the nearest SI magnitude #3

C-Duv opened this issue Feb 21, 2017 · 0 comments

Comments

@C-Duv
Copy link
Contributor

C-Duv commented Feb 21, 2017

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();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant