## Recommended Posts

I have two integers, looted (the total price of all items looted) and the current running time in hours/minutes/seconds.

To get the profit per hour initially, I did

`looted / (hours <= 0 ? 1 : hours)`

The problem with this is, it will only update hourly, and it'll almost always be incorrect as it only goes by the hours. So the script would need to be run for a minimum of 1 hour, then it would only update every hour.

Is it possible to get the current estimated profit per hour from these two integers? (so it'll update every second with an estimated hourly profit)

Edited by Ateria

##### Share on other sites

make yourself timeInHours by doing runtime/1hour(in ms) then you can just do profit/timeInHours for your hourly rate (there is probably a better way but it works)

##### Share on other sites

double profitPerHour = (long) (profit * (3600000.0 / elapsedTimeMs));

This is pretty basic logic but it works like this:

Total Profit / TotalTimeElapsedInMilliseconds = Profit per Millisecond

Then since you want it in hours you times it by the number of milliseconds in an hour (3600000) to now get profit per hour

Edited by battleguard

##### Share on other sites
8 hours ago, battleguard said:

double profitPerHour = (long) (profit * (3600000.0 / elapsedTimeMs));

This is pretty basic logic but it works like this:

Total Profit / TotalTimeElapsedInMilliseconds = Profit per Millisecond

Then since you want it in hours you times it by the number of milliseconds in an hour (3600000) to now get profit per hour

The profit is way off with that, this is the code now:

`double profitPerHour = (long) ((looted * (3600000.0 / elapsedTime))*3600000)/(hours <= 0 ? 1 : hours); `

and here's the estimated profit after running for 16 mins: Edit: Nevermind, this code works as intended, thanks @battleguard

`double profitPerHour = (long) (looted * (3600000.0 / elapsedTime))/(hours <= 0 ? 1 : hours); `

Edited by Ateria
• 1

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account. ×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.