Be a Supporter!

rounding down in php

  • 306 Views
  • 2 Replies
New Topic Respond to this Topic
giantpanda
giantpanda
  • Member since: Jan. 16, 2006
  • Offline.
Forum Stats
Member
Level 11
Blank Slate
rounding down in php 2006-12-05 19:54:06 Reply

I've look all over the intraweb for a php tutorial that might have some idea about what i need.
I wan't to know if it's possible to round down to the nearest interval of 20 in just php.

anyone know how


Be trendy, rebel.

BBS Signature
ListenToMyMusic
ListenToMyMusic
  • Member since: Aug. 12, 2006
  • Offline.
Forum Stats
Member
Level 08
Programmer
Response to rounding down in php 2006-12-05 20:02:25 Reply

yes
<?
echo round(3.123456789012345678905, 20)
?>

makes
3.12345678901234567891

or

echo round(123456789012345678901, -20)

makes

100000000000000000000

whichever you need

or to always round down use this

<?php
function round_down($value)
{
if(is_float($value))
{
$exploded = explode(".",$value);
return $exploded[0];
}
else
{
die("Only float values can be entered.");
}
}
?>

that should help, I may be wrong, so ask others to confirm


come support us at the newgrounds.com irc chat room! - just type your nick, and your in!

henke37
henke37
  • Member since: Sep. 10, 2004
  • Offline.
Forum Stats
Member
Level 30
Blank Slate
Response to rounding down in php 2006-12-06 04:21:13 Reply

floor and ceil forces the rounding direction to be up and down.


Each time someone abuses hittest, God kills a kitten. Please, learn real collision testing.