Skip to content

Commit

Permalink
Fix Xlsx Writer's handling of decimal commas (#1282)
Browse files Browse the repository at this point in the history
Perform the comma -> period substitution in Xlsx Writer writeCell()
before checking if the decimal value has a period in it. The previous
behavior led to decimals of the form "1,1" to become "1.1.0".
  • Loading branch information
makedin authored and Mark Baker committed Jan 3, 2020
1 parent 9fab890 commit ab4c660
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php
Original file line number Diff line number Diff line change
Expand Up @@ -1137,13 +1137,13 @@ private function writeCell(XMLWriter $objWriter, PhpspreadsheetWorksheet $pSheet
case 'n': // Numeric
//force a decimal to be written if the type is float
if (is_float($cellValue)) {
$cellValue = (string) $cellValue;
// force point as decimal separator in case current locale uses comma
$cellValue = str_replace(',', '.', (string) $cellValue);
if (strpos($cellValue, '.') === false) {
$cellValue = $cellValue . '.0';
}
}
// force point as decimal separator in case current locale uses comma
$objWriter->writeElement('v', str_replace(',', '.', $cellValue));
$objWriter->writeElement('v', $cellValue);

break;
case 'b': // Boolean
Expand Down

0 comments on commit ab4c660

Please sign in to comment.