How to: percent from a number
#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


Messages In This Thread
How to: percent from a number - by AndreiWow - 18.02.2017, 21:11
Re: How to: percent from a number - by Unte99 - 18.02.2017, 21:16
Re: How to: percent from a number - by AndreiWow - 18.02.2017, 21:19
Re: How to: percent from a number - by Unte99 - 18.02.2017, 21:30
Re: How to: percent from a number - by Macronix - 18.02.2017, 21:36
Re: How to: percent from a number - by Freaksken - 18.02.2017, 21:44
Re: How to: percent from a number - by iamjems - 19.02.2017, 00:41

Forum Jump:


Users browsing this thread: 1 Guest(s)