Thread: roundTo()
View Single Post
  #6  
Old 08-12-2007, 12:21 PM
zokemon zokemon is offline
That one guy...
zokemon's Avatar
Join Date: Mar 2001
Location: Sonoma County, California
Posts: 2,925
zokemon is a jewel in the roughzokemon is a jewel in the rough
Send a message via ICQ to zokemon Send a message via AIM to zokemon Send a message via MSN to zokemon Send a message via Yahoo to zokemon
Useful but this is a much shorter, simpler and overall less cpu-use way to do it:
(also supports more then just 0.1, 0.01, 0.001, etc.)
PHP Code:
public function roundTo(valplace) {
  return 
int(val/place 0.5)*place;

Two examples:

PHP Code:
myvalue 53.42;
roundTo(myvalue0.1); 
myvalue would be 53.4

PHP Code:
myvalue 53.463;
roundTo(myvalue0.05); 
myvalue would be 53.45

Basically this just takes value and rounds it to the closest "place".

(Didn't see this thread till just now )
__________________
Do it with a DON!
Reply With Quote