Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Release Round float value
#1
This simple function(s) will round a float value to how many decimal places you want:

Code:
roundFloat(floatValue, places)
{
    expValue = exponent(10, places);
    floatValue *= expValue;
    floatValue = int(floatValue);
    floatValue /= expValue;
    return float(floatValue);
}

exponent(basev, exp)
{
    result = 1;
    for(i = 0; i < exp; i++)
        result *= basev;
    return result;
}

Usage:
roundFloat(1.225, 2); //Would return 1.23

And if your wondering how to round a float to the nearest whole number, just use:
int(123.456);
[Image: 30xhrep.png]

A casual conversation between barata and I about Nukem.
Reply

#2
Does the function float() even exist? Thereby roundFloat(1.225, 2) returns 1.22 .
Reply

#3
Dont those functions need to be declared in some way?
How?
Where do you put that piece of code to make it round to a whole number.
[Image: 1314387173_broken.png]

[Image: classic-76561198035631049.png]
Reply

#4
Well where ever you need to use it. -.-
[Image: 30xhrep.png]

A casual conversation between barata and I about Nukem.
Reply

#5
nice work thanks you very much Superman
Reply

#6
How do I do this? :S
Reply



Possibly Related Threads…
Thread Author Replies Views Last Post
  Round Ended MuuRzA737 1 2,226 06-12-2013, 21:34
Last Post: Nekochan
  On "round end" and "round start" DjTranceFire 2 2,738 05-10-2013, 16:07
Last Post: Nekochan
  infected server with different weapons each round szczapek1996 9 5,104 09-21-2012, 11:49
Last Post: szczapek1996
  infected server with different weapons each round (HELP) ryan2pro 2 4,298 09-06-2012, 20:06
Last Post: JariZ
  Reset killtreaks for round sd MILOR123 0 1,723 07-04-2012, 18:23
Last Post: MILOR123
Question Infected: Round ends before last player die AboAlwe 8 4,550 06-01-2012, 16:24
Last Post: DidUknowiPwn
  [Release] Server ender/end round Nukem 55 27,685 03-02-2012, 15:36
Last Post: JariZ
Question SD round limit ham3r 5 3,299 11-11-2011, 08:30
Last Post: koil
  [Solved] Prevent something from resetting next S&D round AZUMIKKEL 4 2,883 09-06-2011, 20:22
Last Post: Pozzuh
Rainbow You spin me right round, baby right round like a record baby right round, round round AZUMIKKEL 7 4,087 09-06-2011, 15:29
Last Post: Cgallagher

Forum Jump:


Users browsing this thread:
1 Guest(s)

Forum Powered By MyBB, Theme by © 2002-2024 Melroy van den Berg.