@@ -80,10 +80,9 @@ function number_to_size($num, int $precision = 1, string $locale=null)
8080 else
8181 {
8282 $ unit = lang ('Number.bytes ' );
83- return number_format ($ num ).' ' .$ unit ;
8483 }
8584
86- return format_number ($ num , $ precision , $ locale). ' ' .$ unit ;
85+ return format_number ($ num , $ precision , $ locale, [ ' after ' => ' ' .$ unit]) ;
8786 }
8887}
8988
@@ -147,7 +146,7 @@ function number_to_amount($num, int $precision, string $locale = null)
147146 $ num = round (($ num /1000 ), $ precision );
148147 }
149148
150- return format_number ($ num , $ precision , $ locale). $ suffix ;
149+ return format_number ($ num , $ precision , $ locale, [ ' after ' => $ suffix]) ;
151150 }
152151}
153152
@@ -175,11 +174,25 @@ function format_number($num, int $precision = 1, string $locale = null, array $o
175174 // Try to format it per the locale
176175 $ output = $ formatter ->format ($ num );
177176
177+ // This might lead a trailing period if $precision == 0
178+ $ output = trim ($ output , '. ' );
179+
178180 if (intl_is_failure ($ formatter ->getErrorCode ()))
179181 {
180182 throw new BadFunctionCallException ($ formatter ->getErrorMessage ());
181183 }
182184
185+ // Add on any before/after text.
186+ if (isset ($ options ['before ' ]) && is_string ($ options ['before ' ]))
187+ {
188+ $ output = $ options ['before ' ].$ output ;
189+ }
190+
191+ if (isset ($ options ['after ' ]) && is_string ($ options ['after ' ]))
192+ {
193+ $ output .= $ options ['after ' ];
194+ }
195+
183196 return $ output ;
184197 }
185198}
0 commit comments