Page 1 of 1

Advanced PHPer needed for identify a decimal function

Posted: Sat Jun 22, 2002 4:03 pm
by Kiwi
Can anyone tell where (if anywhere) it has a function that rounds-up decimals:

Code: Select all

<?php
	$winscore = (int)$winscore;

	// Create a Blank File if it doesn't already exist
	if (!file_exists($filename))
	&#123;
		$file=fopen($filename, "w");
		fclose ($file);
	&#125;

	// Read the file in
	$oscores = file ($filename);
	$numreadin = count($oscores);

	// Break out the data into a new 2-d array called $tscores
	for ($i = 0; $i < $numreadin; $i++)
	&#123;
		$g = unserialize($oscores&#1111;$i]);
		$tscores&#1111;$i]&#1111;0] = $g&#1111;0];
		$tscores&#1111;$i]&#1111;1] = $g&#1111;1];
	&#125;

	// Fill in any missing data with none/0
	for ($i = $numreadin; $i < $scoresize; $i++)
	&#123;
		$tscores&#1111;$i]&#1111;0] = 0;
		$tscores&#1111;$i]&#1111;1] = "none";
	&#125;

	// Process the actions	

	// Insert a score/name
	if ($action == "INSERT")
	&#123;

		// Add name to end of list, and sort
		$tscores&#1111;$scoresize + 1]&#1111;0] = $winscore;
		$tscores&#1111;$scoresize + 1]&#1111;1] = $winname;
		sort ($tscores);

		$file=fopen($filename, "w");

		// Write them out
		for ($i = 0; $i < $scoresize; $i++)
		&#123;
			$st = serialize($tscores&#1111;$i]) . "\n";
			fputs($file, $st);
		&#125;

		fclose($file);
	&#125;

	// Clear the list	
	if ($action == "CLEAR")
	&#123;

		$k&#1111;0] = 0;
		$k&#1111;1] = "none";
		$ser = serialize($k);

		$file=fopen($filename, "w");

		for ($i = 0; $i < $scoresize; $i++)
		&#123;
			$st = $ser . "\n";
			fputs($file, $st);
		&#125;

		fclose($file);
	&#125;

	// Process the OUTPUT options
	if ($viewtype == "HTML")
	&#123;
	  // HTML PAGE CREATED HERE
	  ?>


		<table cellpadding=2 cellspacing=2 border=0 width="152">
		<tr align=center> 
		<th bgcolor="#000033"><font color="#FFFFFF" face="Arial, Helvetica, sans-serif">#</font></th>
		<th bgcolor="#000033"><font color="#FFFFFF" face="Arial, Helvetica, sans-serif">Name</font></th>
		<th bgcolor="#000033"><font color="#FFFFFF" face="Arial, Helvetica, sans-serif">Score</font></th>
		</tr>

   	  <?
	
		for ($i = 0; $i < $scoresize; $i++)
		&#123;
			echo ("<tr bgcolor='#666666' align='center'><td><font size='2' face='Arial, Helvetica, sans-serif'>");
			echo ($i + 1);
			echo ("</font></td><td><font size='2' face='Arial, Helvetica, sans-serif'>");
			echo ($tscores&#1111;$i]&#1111;1]);
			echo ("</font></td><td><font size='2' face='Arial, Helvetica, sans-serif'>");
			echo ($tscores&#1111;$i]&#1111;0]);
			echo ("</font></td></tr>");
		&#125;

  	  ?>
		</table>
	  <?

	&#125;

	// FLASH DATA CREATED HERE
	if ($viewtype == "FLASH")
	&#123;
		for ($i = 0; $i < $scoresize; $i++)
		&#123;
			echo ("NAME" . $i . "=");
			echo ($tscores&#1111;$i]&#1111;1]);
			echo ("&SCORE" . $i . "=");
			echo ($tscores&#1111;$i]&#1111;0]);
			echo ("&");
		&#125;
	&#125;

?>

Posted: Sat Jun 22, 2002 4:17 pm
by volka
$winscore = (int)$winscore;
is a Integer-cast

Posted: Sat Jun 22, 2002 6:02 pm
by will
advanced PHPer?...nothing advanced about this....

round number down - floor()
round number up - ceil()
round to n decimal places round()

(and try not to post all your code if it's not all applicable to your question. sometimes it's helpful, but most of the time just gets in the way) :)

Posted: Sat Jun 22, 2002 8:55 pm
by volka
I think it's ok to post the whole damn thing, because he wanted to know where in this script the score ist rounded to a fractionless number.
[arghhh, it was read and replied to so fast, I have to mark the edit :roll: ]
edit : The funny thing is: It was the first line of instructions ;)

Posted: Sat Jun 22, 2002 8:58 pm
by jason
I would agree with volka here...simply on the grounds that it's better to have the code than not have it. :D

But I do see your point...pasting extra code can be hazardous.

Posted: Sat Jun 22, 2002 9:03 pm
by will
volka wrote:he wanted to know where in this script the score ist rounded
no, the question is
Kiwi wrote:Can anyone tell where (if anywhere) it has a function that rounds-up decimals:
it could be anything... i was under the impression he was referring to PHP in general, as it obviously does have functions to do such a thing.

Posted: Sat Jun 22, 2002 9:17 pm
by volka
ok ok, this was no offense.
When I wrote this I just came home (a little too late for me) and was 'forced' into a (friendly) flamewar in irc, that I obviously lost :(
May be that this affected the post a little :oops:

time for bed now....immediatly

Posted: Sat Jun 22, 2002 9:20 pm
by will
no harm, no foul :)

Posted: Sun Jun 23, 2002 4:33 am
by Kiwi
sorry for posting the whole thing but by trade i'm a flash and actionscript man. i know little if anything of php and i was pretty certain that it wasnt being rounded flash-side so i presumed it must be in the php. and i didnt know where to start :) thanks for the swift answers anyway, it really helped and now the script is all fine and dandy.

Posted: Sun Jun 23, 2002 4:35 am
by Kiwi
PS. i put advanced phper because i usually find more people answer to it :lol: