@@ -205,9 +205,6 @@ public static function format($value, string $format): string
205205 // return 'EUR ' . sprintf('%1.2f', $value);
206206 //}
207207
208- // Some non-number strings are quoted, so we'll get rid of the quotes, likewise any positional * symbols
209- $ format = self ::makeString (str_replace (['" ' , '* ' ], '' , $ format ));
210-
211208 // Find out if we need thousands separator
212209 // This is indicated by a comma enclosed by a digit placeholder:
213210 // #,# or 0,0
@@ -229,20 +226,26 @@ public static function format($value, string $format): string
229226 $ format = self ::pregReplace ('/0,+/ ' , '0 ' , $ format );
230227 $ format = self ::pregReplace ('/#,+/ ' , '# ' , $ format );
231228 }
229+
232230 if (preg_match ('/#?.*\?\/(\?+|\d+)/ ' , $ format )) {
233231 $ value = FractionFormatter::format ($ value , $ format );
234232 } else {
235233 // Handle the number itself
236234
237235 // scale number
238236 $ value = $ value / $ scale ;
237+
239238 // Strip #
240- $ format = self ::pregReplace ('/ \\#/ ' , '0 ' , $ format );
239+ $ format = self ::pregReplace ('/ \\#(?=(?:[^"]*"[^"]*")*[^"]*\Z) / ' , '0 ' , $ format );
241240 // Remove locale code [$-###]
242241 $ format = self ::pregReplace ('/\[\$\-.*\]/ ' , '' , $ format );
243242
244243 $ n = '/ \\[[^ \\]]+ \\]/ ' ;
245244 $ m = self ::pregReplace ($ n , '' , $ format );
245+
246+ // Some non-number strings are quoted, so we'll get rid of the quotes, likewise any positional * symbols
247+ $ format = self ::makeString (str_replace (['" ' , '* ' ], '' , $ format ));
248+
246249 if (preg_match (self ::NUMBER_REGEX , $ m , $ matches )) {
247250 // There are placeholders for digits, so inject digits from the value into the mask
248251 $ value = self ::formatStraightNumericValue ($ value , $ format , $ matches , $ useThousands );
0 commit comments