Thread: roundTo()
View Single Post
  #1  
Old 08-02-2007, 04:58 AM
coreys coreys is offline
N-Pulse Assistant Manager
coreys's Avatar
Join Date: Mar 2005
Posts: 2,180
coreys has a spectacular aura about
Send a message via AIM to coreys Send a message via MSN to coreys Send a message via Yahoo to coreys
roundTo()

Here's a function for rounding to different places (tenths place, hundredths place, etc etc)

PHP Code:
public function roundTo(valplace) {
  
temp.tokens val.tokenize(".");
  if (
temp.tokens[1].substring(place1) < 5temp.decimal temp.tokens[1].substring(place);
  else if (
temp.tokens[1].substring(place1) >= 5temp.decimal temp.tokens[1].substring(01) + 1;
  
temp.newval temp.tokens[0] @ "." temp.decimal;
  return 
temp.newval

Example:
PHP Code:
temp.value 10.56;
temp.newvalue roundTo(temp.value1); //rounds to the tenths place, 2 would round to the hundredths place, 3 to the thousandths place, etc etc
echo(temp.newvalue); 
would return "10.6."
__________________

Quote:
*SlikRick: so should I even ask about your aim status?
*Xor: well if you want to
*Xor: but i am LARPING
*SlikRick: While on a computer?
*Xor: yes
*Xor: in my living room
*SlikRick: ahh
*Xor: i have a fort setup to hide from beasts
Reply With Quote