moneyphp / money

PHP implementation of Fowler's Money pattern.
http://moneyphp.org
MIT License
4.57k stars 440 forks source link

Money::round method reason why is it private? #716

Closed Legion112 closed 1 year ago

Legion112 commented 1 year ago

I have specific business requirements for the MoneyFormatting interface I am implementing.

It should round all Money objects to 8 digits after the decimal point and print it. How could I achieve this? What is the reason the Money::round function is private? Do I need to use some Round interface to round money class?

Legion112 commented 1 year ago

I found solution by using IntlFormatter:

            $formatter = new \NumberFormatter('en-US', \NumberFormatter::DECIMAL);
            $formatter->setAttribute(\NumberFormatter::MIN_FRACTION_DIGITS, 8);
            $formatter->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, 8);
            $formatter->setAttribute(\NumberFormatter::ROUNDING_MODE, \NumberFormatter::ROUND_UP);
            return new IntlMoneyFormatter($formatter, $formatter);