Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Code Gallery (https://forums.graalonline.com/forums/forumdisplay.php?f=179)
-   -   roundTo() (https://forums.graalonline.com/forums/showthread.php?t=76031)

coreys 08-02-2007 04:58 AM

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."

Crow 08-02-2007 10:06 AM

Very nice! I might use that later, thanks a ton :)

coreys 08-02-2007 10:09 AM

Thank Stan for having me make it. lol

Horrified 08-02-2007 10:34 AM

Awesome! I can help 5th Graders with there math homework...on Graal!

Purely, in all standards, deserving the name of v6.

Angel_Light 08-12-2007 05:36 AM

Heh, Graal should be called a Massive Multiplayer Calculator. ;P

zokemon 08-12-2007 12:21 PM

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 >_<)

coreys 08-12-2007 09:05 PM

I hate you...;-;

Inverness 08-12-2007 09:07 PM

Quote:

Originally Posted by coreys (Post 1339372)
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.

coreys 08-13-2007 05:50 AM

lol, nice way of putting it

zokemon 08-13-2007 06:17 AM

I'm sorry :(

xAndrewx 11-09-2014 02:53 PM

thank you. I can round up! :)

rep++ @ Zokemon

Crow 11-09-2014 03:12 PM

Quote:

Originally Posted by xAndrewx (Post 1732486)
thank you. I can round up! :)

rep++ @ Zokemon

This is part of the shared functions package, by the way.

callimuc 11-09-2014 03:22 PM

Quote:

Originally Posted by Crow (Post 1732487)
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

Crow 11-09-2014 05:04 PM

Quote:

Originally Posted by callimuc (Post 1732488)
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.


All times are GMT +2. The time now is 04:45 PM.

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