• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 803
  • Last Modified:

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
0
rcleon
Asked:
rcleon
  • 2
  • 2
  • 2
  • +1
1 Solution
 
8ball629Commented:
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?
0
 
Richard QuadlingSenior Software DeverloperCommented:
THe only reason I can think of is that you are formatting numbers (1234.56 => 1,234.56) to use in a chart and the data is ...

1234.56,2345.67 which now becomes ...

1,234.56,2,345.67

The commas in the numbers in the data being sent to the chart are causing confusion. Maybe.

If you DON'T format the numbers, does the chart work (probably yes), but the chart also shows the numbers?

Are the numbers you want to see formatted the data or the axis?
0
 
Richard QuadlingSenior Software DeverloperCommented:
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.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
star_trekCommented:
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

0
 
rcleonAuthor Commented:
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.
0
 
rcleonAuthor Commented:
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
0
 
8ball629Commented:
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]
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now