PhpSpreadsheet/tests/data/Style/NumberFormat.php
Derek Bonner 01501b6ff2 Remove locale from format string to prevent formatting error (#644)
When a formatting string has a locale in it an error can occur when outputting. For example when the format string with a locale such as `[$-1010409]#,##0.00;-#,##0.00` appears, a value of 9.98 comes back as $9.98. This is because at https://github.com/PHPOffice/PhpSpreadsheet/blob/1.4.0/src/PhpSpreadsheet/Style/NumberFormat.php#L711 the numberFormat regex will match to the zeros inside the locale ([$-1010409]). Attempts to adjust the numberFormat regex caused regressions in other tests. Adding another step to filter out the locale caused no regression.
2018-09-28 21:28:40 +09:00

210 lines
3.1 KiB
PHP

<?php
// value, format, result
return [
[
'0.0',
0.0,
'0.0',
],
[
'0',
0.0,
'0',
],
[
'0.0',
0,
'0.0',
],
[
'0',
0,
'0',
],
[
'000',
0,
'##0',
],
[
'12.0',
12,
'#.0#',
],
[
'0.1',
0.10000000000000001,
'0.0',
],
[
'0',
0.10000000000000001,
'0',
],
[
'5.556',
5.5555000000000003,
'0.###',
],
[
'5.556',
5.5555000000000003,
'0.0##',
],
[
'5.556',
5.5555000000000003,
'0.00#',
],
[
'5.556',
5.5555000000000003,
'0.000',
],
[
'5.5555',
5.5555000000000003,
'0.0000',
],
[
'12,345.68',
12345.678900000001,
'#,##0.00',
],
[
'12,345.679',
12345.678900000001,
'#,##0.000',
],
[
'£ 12,345.68',
12345.678900000001,
'£ #,##0.00',
],
[
'$ 12,345.679',
12345.678900000001,
'$ #,##0.000',
],
[
'5.68',
5.6788999999999996,
'#,##0.00',
],
[
'12,000',
12000,
'#,###',
],
[
12,
12000,
'#,',
],
// Scaling test
[
12.199999999999999,
12200000,
'0.0,,',
],
[
'8%',
0.080000000000000002,
'0%',
],
[
'80%',
0.80000000000000004,
'0%',
],
[
'280%',
2.7999999999999998,
'0%',
],
[
'$125.74 Surplus',
125.73999999999999,
'$0.00" Surplus";$-0.00" Shortage"',
],
[
'$-125.74 Shortage',
-125.73999999999999,
'$0.00" Surplus";$-0.00" Shortage"',
],
[
'$125.74 Shortage',
-125.73999999999999,
'$0.00" Surplus";$0.00" Shortage"',
],
// Fraction
[
'5 1/4',
5.25,
'# ???/???',
],
// Vulgar Fraction
[
'5 3/10',
5.2999999999999998,
'# ???/???',
],
[
'21/4',
5.25,
'???/???',
],
[
'(001) 2-3456-789',
123456789,
'(000) 0-0000-000',
],
[
'0 (+00) 0123 45 67 89',
123456789,
'0 (+00) 0000 00 00 00',
],
[
'12345:67:89',
123456789,
'0000:00:00',
],
[
'-12345:67:89',
-123456789,
'0000:00:00',
],
[
'12345:67.89',
1234567.8899999999,
'0000:00.00',
],
[
'-12345:67.89',
-1234567.8899999999,
'0000:00.00',
],
[
'18.952',
18.952,
'[$-409]General',
],
[
'9.98',
9.98,
'[$-409]#,##0.00;-#,##0.00',
],
[
'18.952',
18.952,
'[$-1010409]General',
],
[
'9.98',
9.98,
'[$-1010409]#,##0.00;-#,##0.00',
],
];