...

View Full Version : Equation question



Strider Xero
01-30-2003, 02:33 AM
Ok, first of all I know close to nothing when it comes to PHP. Yet I know enough to make a template using the simple 'echo' command.

Here's the equation that I have, which works just fine.

<?
$overall = ($action + $comedy + $romancedrama + $voiceacting + $artwork + $plotoriginality) / 6;
?>

This equation works just fine, but my only complaint is that it turns out as like 7.3333333333333333333333

Is there any way that I could simply make it round up to the nearest tenth making it just display 7.3??

Spookster
01-30-2003, 02:38 AM
http://www.php.net/manual/en/function.round.php

Strider Xero
01-30-2003, 03:08 AM
thanks, but sadly i cant understand anything of what was going on in that page. Its way way too advanced for me and I couldnt follow. Ok, instead of rounding, I just want it to display the first digit after the decimal..any ideas?

Spookster
01-30-2003, 03:40 AM
$overall = round((($action + $comedy + $romancedrama + $voiceacting + $artwork + $plotoriginality) / 6),1);



What's hard about that? :cool:

Íkii
01-30-2003, 12:23 PM
for a decimal point or two, you might want number_format

$overall = number_format( (full equation) , 2);

or

$overall = floatval( full equation );
for PHP 4.2.0+

Strider Xero
01-30-2003, 03:02 PM
Okii, THANK YOU!!!!! That was EXACTLY what I wanted to do. Thank God it was so simple, thank you very much!! :thumbsup: :D



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum