FlawlessHappiness 
 
 
		
			Posting Freak 
			
			
			
 
			
	Posts: 3,980 
	Threads: 145 
	Joined: Mar 2012
	
 Reputation: 
171
		
	 | 
	
		
			
Rounding off. 
			 
			
				Hello. 
I searched about rounding off.
 
If I have decimal, say 2.4, I want to round it down to 2. 
If it's 2.7 it should also be rounded down to 2.
 
I found this thread:  https://www.frictionalgames.com/forum/th...ight=round
But did not understand the answer.
 
Can you explain to me how it works?
			  
			
			
 
Trying is the first step to success. 
			
		 |  
	 
 | 
 
	| 08-24-2014, 04:33 PM  | 
	
		
	 | 
 
 
	
		
		Romulator 
 
 
		
			Not Tech Support ;-) 
			
			
			
 
			
	Posts: 3,628 
	Threads: 63 
	Joined: Jan 2013
	
 Reputation: 
195
		
	 | 
	
		
			
RE: Rounding off. 
			 
			
				Well, rounding down is known as "floor" in most codes. 
In the  Math Functions page on the wiki, you can find this riiiiight down the bottom, which with a few clicks, is a copy+paste from the links you were looking at.
 int floor(float &in x) { return int(x); } 
 
 
Only problem is, I got no idea how to use it   
			 
			
			
 
Discord: Romulator#0001
![[Image: 3f6f01a904.png]](https://puu.sh/zOxJg/3f6f01a904.png)  
			
				
(This post was last modified: 08-24-2014, 04:56 PM by Romulator.)
 
				
			 
		 |  
	 
 | 
 
	| 08-24-2014, 04:55 PM  | 
	
		
	 | 
 
 
	
		
		Mudbill 
 
 
		
			Muderator 
			
			
			
 
			
	Posts: 3,881 
	Threads: 59 
	Joined: Apr 2013
	
 Reputation: 
179
		
	 | 
	
		
			
RE: Rounding off. 
			 
			
				My guess would be for such a function to work like so: 
You input the floor(2.7f) into where you need it to be rounded, and it will return 2. For example:
 int iHealthRounded = floor(50.5f); //or whatever number you want to round. float fHealth = iHealthRounded;
  SetPlayerHealth(fHealth); 
 
 
As you probably know, integers can't contain decimals, whereas floats can. It looks like this script simply converts the float (decimal) value to an integer, which kills off the decimal. I'm unsure if this conversion will automatically assume the closest full number or just ignore the decimal though.
 
Don't forget to have that line Rom posted somewhere in your file.
			  
			
			
 
			
				
(This post was last modified: 08-25-2014, 12:25 AM by Mudbill.)
 
				
			 
		 |  
	 
 | 
 
	| 08-24-2014, 05:55 PM  | 
	
		
	 | 
 
 
	
		
		FlawlessHappiness 
 
 
		
			Posting Freak 
			
			
			
 
			
	Posts: 3,980 
	Threads: 145 
	Joined: Mar 2012
	
 Reputation: 
171
		
	 | 
	
		
			
RE: Rounding off. 
			 
			
				What, so the code 
int floor(float &in x) { return int(x); } 
 
 
Actually needs to be in my file, but with nothing editted into it?
			  
			
			
 
Trying is the first step to success. 
			
		 |  
	 
 | 
 
	| 08-24-2014, 07:07 PM  | 
	
		
	 | 
 
 
	
		
		Mudbill 
 
 
		
			Muderator 
			
			
			
 
			
	Posts: 3,881 
	Threads: 59 
	Joined: Apr 2013
	
 Reputation: 
179
		
	 | 
	
		
			
RE: Rounding off. 
			 
			
				Pretty much. It doesn't even need to be named floor. Can be anything. Look at this: 
void Callback() {     int iHealthRounded = ConvertFloatToInt(50.5f);     float fHealth = iHealthRounded;
      SetPlayerHealth(fHealth);  }
  int ConvertFloatToInt(float &in x) {     return int(x); } 
 
  
			 
			
			
 
			
				
(This post was last modified: 08-24-2014, 07:58 PM by Mudbill.)
 
				
			 
		 |  
	 
 | 
 
	| 08-24-2014, 07:58 PM  | 
	
		
	 | 
 
 
	
		
		FlawlessHappiness 
 
 
		
			Posting Freak 
			
			
			
 
			
	Posts: 3,980 
	Threads: 145 
	Joined: Mar 2012
	
 Reputation: 
171
		
	 | 
	
		
			
RE: Rounding off. 
			 
			
				If this works, my damage multiplier will be awesome!   
			 
			
			
 
Trying is the first step to success. 
			
		 |  
	 
 | 
 
	| 08-24-2014, 10:27 PM  | 
	
		
	 | 
 
 
	
		
		MrBehemoth 
 
 
		
			Senior Member 
			
			
			
 
			
	Posts: 408 
	Threads: 19 
	Joined: Feb 2014
	
 Reputation: 
40
		
	 | 
	
		
			
RE: Rounding off. 
			 
			
				Can't you just use something like 
iHealthRounded = int(50.5f);
 ?
			  
			
			
 
			
				
(This post was last modified: 08-24-2014, 11:16 PM by MrBehemoth.)
 
				
			 
		 |  
	 
 | 
 
	| 08-24-2014, 11:16 PM  | 
	
		
	 | 
 
 
	
		
		Daemian 
 
 
		
			Posting Freak 
			
			
			
 
			
	Posts: 1,129 
	Threads: 42 
	Joined: Dec 2012
	
 Reputation: 
49
		
	 | 
	
		
			
RE: Rounding off. 
			 
			
				Just go like this:  int AttackType = ( 2.4 ); 
 
  AttackType=2
( .4 gets eaten,  2 survives the conversion)
 
You can also do:
     float CATS = 2.5;     AddDebugMessage( "I have " + int(CATS) + " cats", false ); 
 
  I have 2 cats
 
What Behe said.
			  
			
			
 
			
				
(This post was last modified: 08-24-2014, 11:41 PM by Daemian.)
 
				
			 
		 |  
	 
 | 
 
	| 08-24-2014, 11:40 PM  | 
	
		
	 | 
 
 
	
		
		MrBehemoth 
 
 
		
			Senior Member 
			
			
			
 
			
	Posts: 408 
	Threads: 19 
	Joined: Feb 2014
	
 Reputation: 
40
		
	 | 
	
		
			
RE: Rounding off. 
			 
			
				Yup. Also, protip: if you want to round of to the  nearest whole number, use
 MyRoundedInt = int(MyFloat + 0.5f);
 
Or if you want to round to a given number of decimal places:
 NearestHundred = int((MyFloat + 0.5f) / 100) * 100; 
NearestHundredth = float(int((MyFloat + 0.5f) * 100)) / 100;
  
			 
			
			
 
			
				
(This post was last modified: 08-30-2014, 02:01 PM by MrBehemoth.)
 
				
			 
		 |  
	 
 | 
 
	| 08-25-2014, 12:25 AM  | 
	
		
	 | 
 
 
	
		
		FlawlessHappiness 
 
 
		
			Posting Freak 
			
			
			
 
			
	Posts: 3,980 
	Threads: 145 
	Joined: Mar 2012
	
 Reputation: 
171
		
	 | 
	
		
			
RE: Rounding off. 
			 
			
				Ok, so this is interesting. 
This is how my script looks.
 
Base damage
 if(GetGlobalVarString("Move") == "Dust")     {         SetLocalVarInt("BaseDamage", RandInt(1,2));     } 
 
 
Damage calculation
 if(GetGlobalVarInt("FriendlyMonsterLevel") != GetLocalVarInt("EnemyMonsterLevel"))         {             SetLocalVarInt("levelDifference", GetGlobalVarInt("FriendlyMonsterLevel")-GetLocalVarInt("EnemyMonsterLevel"));                          SetLocalVarFloat("damageMult", (GetLocalVarInt("levelDifference")/3)*0.5);         }         else         {             SetLocalVarFloat("damageMult", 0);         }
          SetLocalVarFloat("Damage", GetLocalVarInt("BaseDamage")+GetLocalVarFloat("DamageMult"));         if(GetLocalVarFloat("Damage") <= 0)         {             //SetLocalVarFloat("Damage", 0);         }         AddDebugMessage("DAMAGE BEFORE = "+GetLocalVarFloat("damage"), false);         AddLocalVarInt("FriendlyMonsterHealth", -Floor(GetLocalVarFloat("damage")));         AddDebugMessage("DAMAGE = "+GetLocalVarFloat("damage"), false); 
 
 
For some reason end damage = 0 
It really shouldn't
 
EDIT: NEVERMIND! I got it to work.
			  
			
			
 
Trying is the first step to success. 
			
		 |  
	 
 | 
 
	| 08-25-2014, 12:00 PM  | 
	
		
	 | 
 
 
	 
 |