Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > Code Gallery
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #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
  #2  
Old 08-02-2007, 10:06 AM
Crow Crow is offline
ǝɔɐɹq ʎןɹnɔ
Crow's Avatar
Join Date: Dec 2006
Location: Germany
Posts: 5,153
Crow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond repute
Very nice! I might use that later, thanks a ton
__________________
Reply With Quote
  #3  
Old 08-02-2007, 10:09 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
Thank Stan for having me make it. lol
__________________

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
  #4  
Old 08-02-2007, 10:34 AM
Horrified Horrified is offline
Rediculously inactive
Join Date: Jul 2007
Posts: 961
Horrified is on a distinguished road
Send a message via ICQ to Horrified Send a message via AIM to Horrified Send a message via MSN to Horrified Send a message via Yahoo to Horrified
Awesome! I can help 5th Graders with there math homework...on Graal!

Purely, in all standards, deserving the name of v6.
Reply With Quote
  #5  
Old 08-12-2007, 05:36 AM
Angel_Light Angel_Light is offline
Varia Developer
Angel_Light's Avatar
Join Date: Nov 2005
Location: Knoxville, TN
Posts: 1,684
Angel_Light is on a distinguished road
Send a message via AIM to Angel_Light Send a message via MSN to Angel_Light
Heh, Graal should be called a Massive Multiplayer Calculator. ;P
__________________
Deep into the Darkness peering...
Reply With Quote
  #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
  #7  
Old 08-12-2007, 09:05 PM
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
I hate you...;-;
__________________

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
  #8  
Old 08-12-2007, 09:07 PM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
Quote:
Originally Posted by coreys View Post
I hate you...;-;
Yea, I kind of wanted to say "Way to ruin someone's day" to Zero.

But oh well, now you are stronger.
__________________
Reply With Quote
  #9  
Old 08-13-2007, 05:50 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
lol, nice way of putting it
__________________

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
  #10  
Old 08-13-2007, 06:17 AM
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
I'm sorry
__________________
Do it with a DON!
Reply With Quote
  #11  
Old 11-09-2014, 02:53 PM
xAndrewx xAndrewx is offline
Registered User
xAndrewx's Avatar
Join Date: Sep 2004
Posts: 5,260
xAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud of
thank you. I can round up!

rep++ @ Zokemon
__________________
Reply With Quote
  #12  
Old 11-09-2014, 03:12 PM
Crow Crow is offline
ǝɔɐɹq ʎןɹnɔ
Crow's Avatar
Join Date: Dec 2006
Location: Germany
Posts: 5,153
Crow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond repute
Quote:
Originally Posted by xAndrewx View Post
thank you. I can round up!

rep++ @ Zokemon
This is part of the shared functions package, by the way.
__________________
Reply With Quote
  #13  
Old 11-09-2014, 03:22 PM
callimuc callimuc is offline
callimuc's Avatar
Join Date: Nov 2010
Location: Germany
Posts: 1,015
callimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to behold
Quote:
Originally Posted by Crow View Post
This is part of the shared functions package, by the way.
They don't work on mobile servers sadly. But I remember adding a class with all shared functions to Era iPhone, not too sure if it's still around
__________________
MEEP!
Reply With Quote
  #14  
Old 11-09-2014, 05:04 PM
Crow Crow is offline
ǝɔɐɹq ʎןɹnɔ
Crow's Avatar
Join Date: Dec 2006
Location: Germany
Posts: 5,153
Crow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond repute
Quote:
Originally Posted by callimuc View Post
They don't work on mobile servers sadly. But I remember adding a class with all shared functions to Era iPhone, not too sure if it's still around
Ah, good point.
__________________
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 01:55 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.