Open remcotolsma opened 3 years ago
New methods added by @remcotolsma in https://github.com/pronamic/wp-money/commit/a08b3f8d3a4a0434db06d3dea349c9a31c29b3d2:
Money->number_format( $decimals, $decimal_separator, $thousands_separator )
Money->number_format_i18n( $decimals )
In both functions the
$format
parameter is optional, but the parameter doesn't work the same way. Ifnull
is passed inMoney->format_i18n( $format = null )
function it will fall back toMoney::get_default_format()
:https://github.com/pronamic/wp-money/blob/86b41ad9de8ab482be6adbeace317136177fdbcf/src/Money.php#L71-L73
If
null
is passed inMoney->format( $format = null )
function it will fall back to'%2$s'
:https://github.com/pronamic/wp-money/blob/86b41ad9de8ab482be6adbeace317136177fdbcf/src/Money.php#L127-L129
Currently it's very imported that
Money->format( $format = null )
falls back to'%2$s'
, otherwise some of the gateways will break:https://github.com/wp-pay-gateways/mollie/commit/08bc30cbf727a1820f38f99fa76a5bd7cfdf56c1
However, it is not very logical that the
Money->format( $format = null )
does not process currency information by default, without currency information it's just a number.We could make this more clear like this:
Money->format_amount( $number_decimals = null );
, if$number_decimals
isnull
we can fall back to the currency$number_decimals
value, similarly ani18n
version:$money->format_i18n_amount( $number_decimals );
.Naming can also be different:
Money->number_format( $number_decimals = null )
Money->amount_format( $number_decimals = null )
Money->number_format_i18n( $number_decimals = null )
Money->amount_format_i18n( $number_decimals = null )
I think i prefer
number_format
andnumber_format_i18n
:The default format for
Money->format( $format = null )
can then be changed to'%3$s%2$s
' so that it contains at least the currency code by default.Maybe we should also consider replacing the
printf
directives with placeholders:Current use is not very clear:
You have no idea what the result is, following is more clear:
@rvdsteege thoughts?