Jump to content

Calculating Percentage Complete


Galaxy Littlepaws
 Share

You are about to reply to a thread that has been inactive for 1894 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

Okay, I want to be able to calculate how complete an animals' pregnancy is. However, I am unsure if this will calculate correctly.

Here are the relevant excerpts of the script (not the complete script):

float fPregnancy = 172800; //How many seconds the pregnancy lasts
integer preg_time; //How long animal has been pregnant
integer preg_percent; //How complete the pregnancy is


preg_percent = (integer)(preg_time/fPregnancy)*100; //This part should give a percentage complete

Will this calculate correctly? Or is there a better way?

Link to comment
Share on other sites

1 hour ago, BethTech said:

preg_percent = (integer)(preg_time/fPregnancy)*100; //This part should give a percentage complete

Because your variableĀ preg_time is an integer, you ought to typecast it to a float in this calculation and then multiply by 100.0 before converting it to an integer value, so

preg_percent = (integer)(100.0 * (float)preg_time/fPregnancy);
  • Thanks 2
Link to comment
Share on other sites

1 minute ago, Rolig Loon said:

Because your variableĀ preg_time is an integer, you ought to typecast it to a float in this calculation and then multiply by 100.0 before converting it to an integer value, so


preg_percent = (integer)(100.0 * (float)preg_time/fPregnancy);
Ā 

Oh, I see, thanks!

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 1894 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...