How to exponentially increase a variable?

Hi peoples I am working on something and I was curious to know if they had a options to permit to exponentially do a checkup.

what I mean if example you have year who increase.

and I want to create something that EACH time you have a decade it's increase a variables.
so a decade is 10.
How do I tell the system that EACH 10 years. it's increase this variable?

Although the years doesn't reset to zeros it's important!
so if it's reach 10 it's increase the variable and continue so on. if it's reach 20 it's increase the variable again.

How you guys suggest me to aproach this?
What you need to use the modulus operator %
I do not know your context or your code but here is an example.
past this in the console debug to help you undertand

Code:
for (var i = 0; i<100; i++){
    if (i%10===0){
        console.log('Do stuff, i ===', i); // if i can /by 10, do stuff
    }
}
What you need to use the modulus operator %
I do not know your context or your code but here is an example.
past this in the console debug to help you undertand

Code:
for (var i = 0; i<100; i++){
    if (i%10===0){
        console.log('Do stuff, i ===', i); // if i can /by 10, do stuff
    }
}
the code does two thing's :
it's return the number off decade passed. (it's easy to do with a divide and a Math.floor.

the second part work as a boolean if a decade passed between the target year you say and the current year
Code:
public isADecadePassed(targetYear: number) {
  // return true if the distance between the target year and the current years is of 10 years or more.
 
}
Unfortunately I do not understand your goal clearly.
It would take more code to get more help.
Perhaps someone else will understand
the second part work as a boolean if a decade passed between the target year you say and the current year

If I understand correctly, you want to determine whether a "XXX0" year has been hit between the target year and the current year? In that case, divide each by 10, round down, and see if the current year is bigger. It would be something like:

function decadeHasPassed (targetYear, currentYear) {
return ((Math.floor(currentYear / 10)) > (Math.floor(targetYear / 10)))
}

I'm not 100% sure about the syntax - it's been a few months since I've handled JavaScript - but this should at least give you the math you need.

To see how many decades have passed - replace the return line with: return ((Math.floor(currentYear / 10)) - (Math.floor(targetYear / 10)))
it's actually work thanks wavelenght!

If I understand correctly, you want to determine whether a "XXX0" year has been hit between the target year and the current year? In that case, divide each by 10, round down, and see if the current year is bigger. It would be something like:

function decadeHasPassed (targetYear, currentYear) {
return ((Math.floor(currentYear / 10)) > (Math.floor(targetYear / 10)))
}

I'm not 100% sure about the syntax - it's been a few months since I've handled JavaScript - but this should at least give you the math you need.

To see how many decades have passed - replace the return line with: return ((Math.floor(currentYear / 10)) - (Math.floor(targetYear / 10)))
Thread closed IgnoreMe

Original thread: https://forums.rpgmakerweb.com/threads/how-to-exponentially-increase-a-variable.78131/