• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!
  • 2026 staff recruitment is open! Check it out and consider applying!

Round an PHP value

Dankoo

Active Member
Joined
Sep 4, 2010
Messages
1,007
Reaction score
27
How do I set an value like this: 86.43% to be shown like 86%?

I've tried with (int) code

But it hides float numbers and only show integers, I want one that rounds the value for it to become integer xD

PHP:
            $questCount   = $questCount + 1; $questStatus = $SQL->query("SELECT * FROM `player_storage` WHERE `player_id` = ".$id." AND `key` = ".$questData["storageid"].";")->fetch();
            $questPercent = (($questStatus["value"] - $questData["startvalue"])/$questData["endvalue"]) * 100;
            $main_content         .= "<center><table WIDTH=50%><td width=\"55%\">".$questName."</td><td width=\"45%\" style=\"text-align:center;\">".$questPercent."%<div style=\"background-color:white; margin-top:-14px; width: 100%; height: 12px; border: 1px solid #DDD;\"><div style=\"background: green; width: ".$questPercent."%; height: 12px;\"></div></div></td></tr></table></center>";
 
I've tried... Something like this?

PHP:
$questPercent = round((($questStatus["value"] - $questData["startvalue"])/$questData["endvalue"]) * 100;)

Tried also:

PHP:
 $questPercent = (int)(($questStatus["value"] - $questData["startvalue"])/$questData["endvalue"]) * 100;
Wich returns me only integer values
 
despion0, you might help with this...

PHP:
<script>
            $( document ).ready( function( ) {
                $( '#toggleQuests' ).click( function( ) {
                    if ( $( '#contentQuests' ).is( ':visible' ) ) {
                        $( '#contentQuests' ).slideUp( 'fast' );
                        $( this ).html( 'Show/Hide' );
                        return;
                    }
                $( '#contentQuests' ).slideDown( 'fast' );
                $( this ).html( 'Show/Hide' );
                } );
            } );
        </script>

I'm trying to change the font color for 'Show/Hide', any ideas?
 
Try this
Code:
<script>
$(document).ready(function(){
	$('#toggleQuests').click(function()
	{
		if ($('#contentQuests').is(':visible'))
		{
			$('#contentQuests').slideUp('fast');
			$(this).html('<span style="color:green;">Show/Hide</span>');
			return;
		}
		$('#contentQuests').slideDown('fast');
		$(this).html('<span style="color:red;">Show/Hide</span>');
	});
});
</script>
 
Returns blank page on Gesior

PS: tried replacing the "" for ' ' and it opened the page.. But script stopped working

Like:

PHP:
<span style='color:red;'>Show/Hide</span>
Instead of:
PHP:
<span style="color:red;">Show/Hide</span>
 
Ya, it's using jQuery, error reporting enabled and:

Parse error: syntax error, unexpected T_STRING in /var/www/characters.php on line 282

Line 282
PHP:
			$(this).html('<span style="color:green;">Show/Hide</span>');
 
Code:
<script>
$(document).ready(function(){
	$('#toggleQuests').click(function()
	{
		if ($('#contentQuests').is(':visible'))
		{
			$('#contentQuests').slideUp('fast');
			$(this).html('<span style=\"color:green;\">Show/Hide</span>');
			return;
		}
		$('#contentQuests').slideDown('fast');
		$(this).html('<span style=\"color:red;\">Show/Hide</span>');
	});
});
</script>
 
Oh, there's just one more thing that annoys me in this stuff...

When click for hide/show, it goes to the top of the page, is there a way to avoid it?



PHP:
<script>
$(document).ready(function(){
	$('#toggleQuests').click(function()
	{
		if ($('#contentQuests').is(':visible'))
		{
			$('#contentQuests').slideUp('fast');
			$(this).html('<span style=\"color:green;\">Show/Hide</span>');
			return;
		}
		$('#contentQuests').slideDown('fast');
		$(this).html('<span style=\"color:red;\">Show/Hide</span>');
	});
});
</script>

<B>Quests (<a href="#" id="toggleQuests"><FONT COLOR="#41A317">Show/Hide</FONT></a>)</B>
 
Oh, there's just one more thing that annoys me in this stuff...

When click for hide/show, it goes to the top of the page, is there a way to avoid it?



PHP:
<script>
$(document).ready(function(){
	$('#toggleQuests').click(function()
	{
		if ($('#contentQuests').is(':visible'))
		{
			$('#contentQuests').slideUp('fast');
			$(this).html('<span style=\"color:green;\">Show/Hide</span>');
			return;
		}
		$('#contentQuests').slideDown('fast');
		$(this).html('<span style=\"color:red;\">Show/Hide</span>');
	});
});
</script>

<B>Quests (<a href="#" id="toggleQuests"><FONT COLOR="#41A317">Show/Hide</FONT></a>)</B>

*-*
 
Back
Top