How to: percent from a number
#1

Hey guys, I want to make a percent system that will tell you the stage of something, for example.


This is 36% done.

For example, I will have my variable set to 60. which means one hour, 60 minutes, I will have a timer that will lower 1 every second, the thing is, how can I get the percent from that variable? Like, if it is 0, the text will show.

This is 100%! COMPLETED!

but if the variable is 60 the text will show.

This is 0% completed. I think you got what I mean, I want the percent to update with the variable.


Something like this? Like if the variable is 6 it should be 10% because, 10/100 * 60 = 6 but how can I do this in pawn?
Reply
#2

http://www.basic-mathematics.com/for...ercentage.html
Reply
#3

Quote:
Originally Posted by Unte99
Посмотреть сообщение
I don't know how to do it in pawn....

x/100*60 = my variable stage.. would be but I don't know how to make pawn find the x number.
Reply
#4

Quote:
Originally Posted by AndreiWow
Посмотреть сообщение
I don't know how to do it in pawn....

x/100*60 = my variable stage.. would be but I don't know how to make pawn find the x number.
First of all, you have to think of where you are going to do the calculations. Maybe you would want to make a percentage function which you could use where ever you want. Or maybe you would just want to make a script which would calculate the percentage in a command.

When you think of the place where you want to create it, you just make a simple code like this one:

Код:
new percentagenumber, number;

percentagenumber=number/100*60;
Reply
#5

(1 - (Your variable / 60)) * 100 ?
Reply
#6

The percentage calculation is just maths.
Код:
% = 100 - (currentValue / maxValue * 100)

//Say maxValue is 60
//At the start: 0% = 100 - (60 / 60 * 100)
//At the middle: 50% = 100 - (30 / 60 * 100)
//At the end: 100% = 100 - (0/ 60 * 100)
When implementing this in pawn, beware of integer division, so use floats.
Implementation method:
  • Before the start of the timer, set maxValue.
  • Before the start of the timer, set currentValue to maxValue.
  • With every tick of the timer, decrease currentValue and update the string if needed.
Reply
#7

x = percentage * y / 100;
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)