Skip to content

Commit a0859fd

Browse files
author
Mark Baker
committed
Fix to number format masking for scientific notation
1 parent 8f7db24 commit a0859fd

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

Classes/PHPExcel/Style/NumberFormat.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,10 @@ public static function toFormattedString($value = '0', $format = PHPExcel_Style_
673673
);
674674
$value = preg_replace($number_regex, $value, $format);
675675
} else {
676-
if (preg_match('/0([^\d\.]+)0/', $format, $matches)) {
676+
if (preg_match('/0E[+-]0/i', $format)) {
677+
// Scientific format
678+
$value = sprintf('%5.2E', $value);
679+
} elseif (preg_match('/0([^\d\.]+)0/', $format)) {
677680
$value = self::_complexNumberFormatMask($value, $format);
678681
} else {
679682
$sprintf_pattern = "%0$minWidth." . strlen($right) . "f";
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
123.456, '"$#,##0.00"', "$123.46"
2-
123.456, '"#,##0.00"', "123.46"
3-
123.456, '"#,##0"', "123"
4-
123.456, "00000", "00123"
5-
123456.789, '"$#,##0.00"', '"$123,456.79"'
6-
123456.789, '"#,##0.00"', '"123,456.79"'
7-
123456.789, "0.00E+00", "1.23E05"
1+
123.456, '"$#,##0.00"', "$123.46"
2+
-123.456, '"$#,##0.00"', "$-123.46"
3+
123.456, '"#,##0.00"', "123.46"
4+
123.456, '"#,##0"', "123"
5+
123.456, "00000", "00123"
6+
123456.789, '"$#,##0.00"', '"$123,456.79"'
7+
123456.789, '"#,##0.00"', '"123,456.79"'
8+
123456.789, "0.00E+00", "1.23E05"
9+
-123456.789, "0.00E+00", "-1.23E05"
10+
0.000012345, "0.00E+00", "1.23E-05"
811
"19-Dec-1960", "yyyy-mm-dd", "1960-12-19"
912
"1-Jan-2012", "yyyy-mm-dd", "2012-01-01"
10-
1.75, "# ?/?", "1 3/4"
13+
1.75, "# ?/?", "1 3/4"

0 commit comments

Comments
 (0)