Page 1 of 1

Help with decimal Places

Posted: Thu Mar 04, 2004 10:42 pm
by ]{ronic
Hey,

Im no php guru, just a newbie ...

my data is stored in excel file .. I use a programe to convert it to a sql file which is all good .. the problem I am having is in excel, the price cell is formated to show $ + 0 decimal places .. when it is converted to a sql file it drops the formating to no symbol and 1 decimal place ...

Is it posible to force it to 0 decimals so it is just 10 rather than 10.3?

Also an if statement so if there is no data in the mysql price cell .. return blank (so that cell has no data printed).

Any help on the intergration of the above would be great as I have tried a few ideas with no luck .. but again I am a newbie.


Below is a copy of my script:

Code: Select all

for ($i = 0; $i < $numofrows; $i++) &#123;
$row = mysql_fetch_assoc($result);
if ($i % 2) &#123;
echo "<TR bgcolor="#CCCCCC">\n";
&#125; else &#123;
echo "<TR bgcolor="#0099CC">\n";
&#125;
echo "<TD>".$row&#1111;'description']."</TD><TD align="right">\$".$row&#1111;'price']."</TD><TD>";

$image = $row&#1111;'link'];

if ($image)
echo "<a href="$image" target="new"><strong><center>Link</center></strong></a>";
else
echo "<center></center>";

echo "</TD></TR>\n";

Thanks

]{ronic

Posted: Fri Mar 05, 2004 1:46 am
by Weirdan
[php_man]round[/php_man]

Code: Select all

//........skipped.....
echo "<TD>".$row['description']."</TD><TD align="right">\$".round($row['price'])."</TD><TD>";
//.........skipped

Posted: Fri Mar 05, 2004 3:16 am
by ]{ronic
Hey Weirdan,

Thanks for that .. works like a charm.

I have been trying to get an "if" function in there as well .. So if the data base holds no records in the "price" cell display nothing rather than $0

Any ideas on that .. how I have tried it is leaving out the cell totally for the rows that have no data in it.


Thanks

]{ronic

Posted: Fri Mar 05, 2004 3:58 am
by Weirdan

Code: Select all

//........skipped..... 
if(round($row['price']))
  $price_field=round($row['price']);
else $price_field="";
echo "<TD>".$row['description']."</TD><TD align="right">\$".$price_field."</TD><TD>"; 
//.........skipped

Posted: Fri Mar 05, 2004 4:49 am
by ]{ronic
Hey ..

Thanks dewd that does it .. except that the $ stills displays in the empty cell .. Is the way the $ is incorporated a plausable way to do it?

Thanks

]{ronic

Posted: Fri Mar 05, 2004 12:20 pm
by Weirdan
sure:

Code: Select all

//........skipped..... 
if(round($row['price'])) 
  $price_field="\$".round($row['price']); 
else $price_field=""; 
echo "<TD>".$row['description']."</TD><TD align="right">".$price_field."</TD><TD>"; 
//.........skipped

Posted: Sat Mar 06, 2004 4:47 am
by ]{ronic
Hey Weirdan,

That does the job perfectly .. Thank you very much for your input/time

]{ronic