Quote:
Originally Posted by Cristian505
Is there a way to get the percentage between two numbers?
I mean something like 1000 - 100 = 90% from 1000
"You have passed 90% from 1000"
|
Yes, it's called division.
Quote:
Originally Posted by Moody92
Post your code, if you make the 1000 a variable it'd be better
PHP Code:
new total = 1000 // Total
new cProgress = 900 // Current progress, I am assigning numbers here just for example
new cParam // calculation parameter
cParam = ((total - cProgress) / total)*100
client_print(id, print_chat, "You have passed %d%%%% from %d", cParam, total) // the %%%% is to print the % in chat
|
No, that is incorrect for two reasons. First, to get the percentage of the total progress, you simply divide the actual value by the total value (cProgress/Total)*100.
The other thing is that you're using integers so you are doing integer division which will means that cProgress / Total will always result in 0 provided that cProgress is less than Total.
To be able to do this, you need to convert to floating point values before doing the division. Alternatively, if you don't need the full precision, you can use integer division but you need to multiply cProgress by 100 first and then divide by Total: (cProgress * 100) / Total. This will effectively be the truncated value of the method using floating point values.
__________________