Jump to content

[SOLVED] Adding a decimal to an output echo


suttercain

Recommended Posts

Good morning everyone,

 

I have a question. I know it's pretty basic but I was unable to find the answer on my own on php.net so maybe someone can help me out.

 

I am echoing a varchar column from a MySQL database. In this column I have some integers and some doubles. Exp: 1.5, 2, 3.0, 5.

 

WHAT I NEED:

The numbers that already have a decimal are echoed in the correct format. I need the numbers with no decimal (2, 5, etc.) to be echoed with one decimal to match the others in the column. Exp: I need 2 to be echoed as 2.0, 5 as 5.0, etc.

 

Here is the code that is being echoed:

  echo "<tr class=\"$class\">\n";
  echo "<td>$row[sub_class]</td>\n";
  echo "<td>$row[disp] L</td>\n";
  echo "<td>$row[fuel]</td>\n";   <--------------- THIS IS WHERE I NEED THE DECIMAL POINT
  echo "</tr>\n";

 

Anyone have any suggestions?

 

Thank you in advance.

 

  echo "<tr class=\"$class\">\n";
  echo "<td>$row[sub_class]</td>\n";
  echo "<td>$row[disp] L</td>\n";
  echo "<td>".sprintf( '%01.1f',$row[fuel])."</td>\n";   <--------------- THIS IS WHERE I NEED THE DECIMAL POINT
  echo "</tr>\n";

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.