Advanced PHPer needed for identify a decimal function

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Kiwi
Forum Newbie
Posts: 3
Joined: Sat Jun 22, 2002 4:03 pm

Advanced PHPer needed for identify a decimal function

Post 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;

?>
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

$winscore = (int)$winscore;
is a Integer-cast
will
Forum Contributor
Posts: 120
Joined: Fri Jun 21, 2002 9:38 am
Location: Memphis, TN

Post 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) :)
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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 ;)
Last edited by volka on Sat Jun 22, 2002 9:00 pm, edited 2 times in total.
jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Post 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.
will
Forum Contributor
Posts: 120
Joined: Fri Jun 21, 2002 9:38 am
Location: Memphis, TN

Post 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.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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
will
Forum Contributor
Posts: 120
Joined: Fri Jun 21, 2002 9:38 am
Location: Memphis, TN

Post by will »

no harm, no foul :)
Kiwi
Forum Newbie
Posts: 3
Joined: Sat Jun 22, 2002 4:03 pm

Post 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.
Kiwi
Forum Newbie
Posts: 3
Joined: Sat Jun 22, 2002 4:03 pm

Post by Kiwi »

PS. i put advanced phper because i usually find more people answer to it :lol:
Post Reply