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
Kiwi
Forum Newbie
Posts: 3 Joined: Sat Jun 22, 2002 4:03 pm
Post
by Kiwi » Sat Jun 22, 2002 4:03 pm
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))
{
$file=fopen($filename, "w");
fclose ($file);
}
// 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++)
{
$g = unserialize($oscoresї$i]);
$tscoresї$i]ї0] = $gї0];
$tscoresї$i]ї1] = $gї1];
}
// Fill in any missing data with none/0
for ($i = $numreadin; $i < $scoresize; $i++)
{
$tscoresї$i]ї0] = 0;
$tscoresї$i]ї1] = "none";
}
// Process the actions
// Insert a score/name
if ($action == "INSERT")
{
// Add name to end of list, and sort
$tscoresї$scoresize + 1]ї0] = $winscore;
$tscoresї$scoresize + 1]ї1] = $winname;
sort ($tscores);
$file=fopen($filename, "w");
// Write them out
for ($i = 0; $i < $scoresize; $i++)
{
$st = serialize($tscoresї$i]) . "\n";
fputs($file, $st);
}
fclose($file);
}
// Clear the list
if ($action == "CLEAR")
{
$kї0] = 0;
$kї1] = "none";
$ser = serialize($k);
$file=fopen($filename, "w");
for ($i = 0; $i < $scoresize; $i++)
{
$st = $ser . "\n";
fputs($file, $st);
}
fclose($file);
}
// Process the OUTPUT options
if ($viewtype == "HTML")
{
// 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++)
{
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ї$i]ї1]);
echo ("</font></td><td><font size='2' face='Arial, Helvetica, sans-serif'>");
echo ($tscoresї$i]ї0]);
echo ("</font></td></tr>");
}
?>
</table>
<?
}
// FLASH DATA CREATED HERE
if ($viewtype == "FLASH")
{
for ($i = 0; $i < $scoresize; $i++)
{
echo ("NAME" . $i . "=");
echo ($tscoresї$i]ї1]);
echo ("&SCORE" . $i . "=");
echo ($tscoresї$i]ї0]);
echo ("&");
}
}
?>
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Sat Jun 22, 2002 4:17 pm
$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 » Sat Jun 22, 2002 6:02 pm
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)
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Sat Jun 22, 2002 8:55 pm
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
]
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 » Sat Jun 22, 2002 8:58 pm
I would agree with volka here...simply on the grounds that it's better to have the code than not have it.
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 » Sat Jun 22, 2002 9:03 pm
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.
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Sat Jun 22, 2002 9:17 pm
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
time for bed now....immediatly
will
Forum Contributor
Posts: 120 Joined: Fri Jun 21, 2002 9:38 am
Location: Memphis, TN
Post
by will » Sat Jun 22, 2002 9:20 pm
no harm, no foul
Kiwi
Forum Newbie
Posts: 3 Joined: Sat Jun 22, 2002 4:03 pm
Post
by Kiwi » Sun Jun 23, 2002 4:33 am
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 » Sun Jun 23, 2002 4:35 am
PS. i put advanced phper because i usually find more people answer to it