Link to home
Start Free TrialLog in
Avatar of rcleon
rcleonFlag for United States of America

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
Avatar of 8ball629
8ball629
Flag of United States of America image

Well, I'm not sure why it would be choking on number_format.  That seems to be the best route to go and if you don't want decimals do you want to round the number?

 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?
ASKER CERTIFIED SOLUTION
Avatar of Richard Quadling
Richard Quadling
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
Avatar of star_trek
star_trek

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

Avatar of rcleon

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,$format);

            $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.
Avatar of rcleon

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
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]