Skip to content

Commit

Permalink
Add support for one digit decimals (FORMAT_NUMBER_0, FORMAT_PERCENTAG…
Browse files Browse the repository at this point in the history
…E_0) (#2525)

* Add support for one digit decimals (FORMAT_NUMBER_0)

* Add support for one digit decimals (FORMAT_NUMBER_0, FORMAT_PERCENTAGE_0)

* adding tests for one digit numbers

* cleanup

* add failing test to block merge of this PR until #2555 has been merged

* fix code style

* fix test
  • Loading branch information
nohn authored Feb 5, 2022
1 parent b5c03fc commit 454c01b
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ and this project adheres to [Semantic Versioning](https://semver.org).
- Full support of the above CF Rules for the Xlsx Reader and Writer; even when the file being loaded has CF rules listed in the `<extLst><ext><ConditionalFormattings>` element for the worksheet rather than the `<ConditionalFormatting>` element.
- Provision of a CellMatcher to identify if rules are matched for a cell, and which matching style will be applied.
- Improved documentation and examples, covering all supported CF rule types.
- Add support for one digit decimals (FORMAT_NUMBER_0, FORMAT_PERCENTAGE_0)

### Changed

Expand Down
2 changes: 2 additions & 0 deletions src/PhpSpreadsheet/Style/NumberFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ class NumberFormat extends Supervisor
const FORMAT_TEXT = '@';

const FORMAT_NUMBER = '0';
const FORMAT_NUMBER_0 = '0.0';
const FORMAT_NUMBER_00 = '0.00';
const FORMAT_NUMBER_COMMA_SEPARATED1 = '#,##0.00';
const FORMAT_NUMBER_COMMA_SEPARATED2 = '#,##0.00_-';

const FORMAT_PERCENTAGE = '0%';
const FORMAT_PERCENTAGE_0 = '0.0%';
const FORMAT_PERCENTAGE_00 = '0.00%';

const FORMAT_DATE_YYYYMMDD2 = 'yyyy-mm-dd';
Expand Down
115 changes: 115 additions & 0 deletions tests/data/Style/NumberFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,61 @@
'1.9',
NumberFormat::FORMAT_NUMBER,
],
[
'1.0',
'1.000',
NumberFormat::FORMAT_NUMBER_0,
],
[
'-1.0',
'-1.000',
NumberFormat::FORMAT_NUMBER_0,
],
[
'1.0',
'1',
NumberFormat::FORMAT_NUMBER_0,
],
[
'-1.0',
'-1',
NumberFormat::FORMAT_NUMBER_0,
],
[
'1.0',
'1',
NumberFormat::FORMAT_NUMBER_0,
],
[
'0.0',
'0',
NumberFormat::FORMAT_NUMBER_0,
],
[
'0.0',
'-0',
NumberFormat::FORMAT_NUMBER_0,
],
[
'1.1',
'1.11',
NumberFormat::FORMAT_NUMBER_0,
],
[
'1.1',
'1.14',
NumberFormat::FORMAT_NUMBER_0,
],
[
'1.2',
'1.15',
NumberFormat::FORMAT_NUMBER_0,
],
[
'1.2',
'1.19',
NumberFormat::FORMAT_NUMBER_0,
],
[
'0.00',
'0',
Expand Down Expand Up @@ -831,6 +886,66 @@
'-0.019',
NumberFormat::FORMAT_PERCENTAGE,
],
[
'0.0%',
'0',
NumberFormat::FORMAT_PERCENTAGE_0,
],
[
'1.0%',
'0.01',
NumberFormat::FORMAT_PERCENTAGE_0,
],
[
'1.1%',
'0.011',
NumberFormat::FORMAT_PERCENTAGE_0,
],
[
'1.1%',
'0.0114',
NumberFormat::FORMAT_PERCENTAGE_0,
],
[
'1.2%',
'0.0115',
NumberFormat::FORMAT_PERCENTAGE_0,
],
[
'1.2%',
'0.0119',
NumberFormat::FORMAT_PERCENTAGE_0,
],
[
'0.0%',
'-0',
NumberFormat::FORMAT_PERCENTAGE_0,
],
[
'-1.0%',
'-0.01',
NumberFormat::FORMAT_PERCENTAGE_0,
],
[
'-1.1%',
'-0.011',
NumberFormat::FORMAT_PERCENTAGE_0,
],
[
'-1.1%',
'-0.0114',
NumberFormat::FORMAT_PERCENTAGE_0,
],
[
'-1.2%',
'-0.0115',
NumberFormat::FORMAT_PERCENTAGE_0,
],
[
'-1.2%',
'-0.0119',
NumberFormat::FORMAT_PERCENTAGE_0,
],
[
'0.00%',
'0',
Expand Down

0 comments on commit 454c01b

Please sign in to comment.