Scripting + Math

Post » Mon Mar 14, 2011 6:32 pm

In the script I am working on updatning my battery charger mod to include a "Convert all" option. To keep this short, lets say I have 3952 MFC and i want to change them to Fission Batteris as per my conversion rates, if I divide that by 25 I get 158.08. Now the problem is, I need to get rid of that extra .08 in order to progress with the script commands I need to run.

Example:
Set iTempA To Player.GetItemCount AmmoMicroFusionCell     Set iTempB To iTempA/25


Help?
User avatar
CYCO JO-NATE
 
Posts: 3431
Joined: Fri Sep 21, 2007 12:41 pm

Post » Tue Mar 15, 2011 1:04 am

I think if you make ITempB a short instead of float variables, it will not have any decimal places correct?
User avatar
Soku Nyorah
 
Posts: 3413
Joined: Tue Oct 17, 2006 1:25 pm

Post » Tue Mar 15, 2011 4:27 am

That's correct - when a floating point value such as 158.08 is assigned to an integer variable (i.e one declared using the "int", "short" or "long" keyword), the value will be truncated (i.e. rounded down) after the decimal point. If you want to round values up as well as down, then add 0.5 before assigning them.

Cipscis
User avatar
J.P loves
 
Posts: 3487
Joined: Thu Jun 21, 2007 9:03 am

Post » Mon Mar 14, 2011 7:49 pm

I see, so int and short don't record the decimal. Useful to know and easy to understand. XD

Thanks a lot! should make the rest of my work really smooth.
User avatar
Krista Belle Davis
 
Posts: 3405
Joined: Tue Aug 22, 2006 3:00 am


Return to Fallout 3

cron