Reputation: 3294
I'm using PHPExcel to print some money amount, and I need them to have 4 decimal numbers after comma, but I want to remove any trailing zero. For example, my input is:
Input: 11,1230 => Wanted output: 11,123
Input: 0,0123 => Wanted output: 0,0123
Input: 8,3200 => Wanted output: 8,32
Input: 44,0000 => Wanted output: 44 <--error is here
The problem is that I can't get rid of the trailing comma of 44,0000
which prints out as 44,
I'm using the following command:
$activeSheet->getStyle("K10")->getNumberFormat()->setFormatCode('€ ####0.####');
All numbers print as expected except for those numbers without significant decimals value, like 44,0000. Any idea?
EDIT: I know I can use MS Excel to achieve this, by using these buttons
but I would prefer a PHP solution
Upvotes: 1
Views: 1486
Reputation: 212522
Perhaps you meant to use
€ ####0.0000
or
€ ####0.0###
rather than
€ ####0.####
The #
is telling MS Excel only to display digits in that position where necessary, whereas 0
is telling MS Excel always to display digits in that position (even if that digit is only a 0
)
But if you use .####
, MS Excel will always display the decimal separator, even if there are no digits to display following it unless you use conditional formatting with a formula like =MOD(A1,1)>0
Upvotes: 1
Reputation: 5410
I think you need a solution from excel because your final result will be visible from a excel sheet and your requirement seems not to be possible only using number formatting. My suggestion is to add conditional number formatting from PHPExcel. Here shows how it is done using excel.
OR
You may have to override PHPExcel classes.
Upvotes: 0