rcleon
asked on
Formating numbers
Hi,
is there a way to format number without using format_number I'm using fpdf to output some graph and if I use number_format it get confused. I do not know why but it dose.
I only need to format the number for printing 87.12345678 just wont cut it I need to display 87 or 12345.12345678 just wont do I need to display 12,345 is there a way to acomplish this?
my out put goes from 87 dollars to as high as 78,564.
Thanks
Rafael
is there a way to format number without using format_number I'm using fpdf to output some graph and if I use number_format it get confused. I do not know why but it dose.
I only need to format the number for printing 87.12345678 just wont cut it I need to display 87 or 12345.12345678 just wont do I need to display 12,345 is there a way to acomplish this?
my out put goes from 87 dollars to as high as 78,564.
Thanks
Rafael
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
And to format a number with no decimal part ...
number_format($value, 0);
Rounding like 8ball629 suggested, is probably a not a good idea, but that depends upon the data and what the chart is showing.
number_format($value, 0);
Rounding like 8ball629 suggested, is probably a not a good idea, but that depends upon the data and what the chart is showing.
if you are retrieving the values from database, you can try formatting from the database.
For example for MySQL
select format(12345.78,0)
would return 12,346
For example for MySQL
select format(12345.78,0)
would return 12,346
ASKER
I think you guys are right it is the commas and/or the decimal here is the portion of the calc.
function BarDiagram($w, $h, $data, $format, $color=null, $maxVal=0, $nbDiv=4)
{
$this->SetFont('Arial', 'B', 10);
$this->SetLegends($data,$f ormat);
$XPage = $this->GetX();
$YPage = $this->GetY();
$margin = 2;
$YDiag = $YPage + $margin;
$hDiag = floor($h - $margin * 2);
$XDiag = $XPage + $margin * 2 + $this->wLegend;
$lDiag = floor($w - $margin * 3 - $this->wLegend);
if($color == null)
$color=array(155,155,155);
if ($maxVal == 0) {
$maxVal = max($data);
}
$valIndRepere = ceil($maxVal / $nbDiv);
$maxVal = $valIndRepere * $nbDiv;
$lRepere = floor($lDiag / $nbDiv);
$lDiag = $lRepere * $nbDiv;
$unit = $lDiag / $maxVal;
$hBar = floor($hDiag / ($this->NbVal + 1));
$hDiag = $hBar * ($this->NbVal + 1);
$eBaton = floor($hBar * 80 / 100);
Any help will be appricated.
Rafael
I send more that what I think you would need but I wanted to make sure you could see the parameters of the function.
function BarDiagram($w, $h, $data, $format, $color=null, $maxVal=0, $nbDiv=4)
{
$this->SetFont('Arial', 'B', 10);
$this->SetLegends($data,$f
$XPage = $this->GetX();
$YPage = $this->GetY();
$margin = 2;
$YDiag = $YPage + $margin;
$hDiag = floor($h - $margin * 2);
$XDiag = $XPage + $margin * 2 + $this->wLegend;
$lDiag = floor($w - $margin * 3 - $this->wLegend);
if($color == null)
$color=array(155,155,155);
if ($maxVal == 0) {
$maxVal = max($data);
}
$valIndRepere = ceil($maxVal / $nbDiv);
$maxVal = $valIndRepere * $nbDiv;
$lRepere = floor($lDiag / $nbDiv);
$lDiag = $lRepere * $nbDiv;
$unit = $lDiag / $maxVal;
$hBar = floor($hDiag / ($this->NbVal + 1));
$hDiag = $hBar * ($this->NbVal + 1);
$eBaton = floor($hBar * 80 / 100);
Any help will be appricated.
Rafael
I send more that what I think you would need but I wanted to make sure you could see the parameters of the function.
ASKER
Thank you guys,
I took the hint from RQ an was able to rewrite the function taking into consideration the comma. If this had not been suggested I would have never found the solution.
Thanks
Rafael
I took the hint from RQ an was able to rewrite the function taking into consideration the comma. If this had not been suggested I would have never found the solution.
Thanks
Rafael
For the record, the reason I was suggesting round it is because of the following:
[quote]
I only need to format the number for printing 87.12345678 just wont cut it I need to display 87 or 12345.12345678 just wont do I need to display 12,345 is there a way to acomplish this?
[/quote]
[quote]
I only need to format the number for printing 87.12345678 just wont cut it I need to display 87 or 12345.12345678 just wont do I need to display 12,345 is there a way to acomplish this?
[/quote]
If so try...
number_format(round($int, 0));
There may be a better solution but I've never had problems with number_format before.. What exact problems did you see with the number_format?