cancel
Showing results for 
Search instead for 
Did you mean: 

How to calculate modulas of two numbers using script

former_member219118
Participant
0 Kudos

Hi Experts,

Can anyone tell me how to calculate modulas of two numbers in design studio.

Eg: I want to calculate given year is a Leap year or not.

Normal logic is : ((year %4 ==0) && ((year%100!=0) || (year%400) ==0)).

Here in script it is not allowing to use % for modulas.

Please suggest me probable solution.

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

a % b equals: a - (n * int(a/n))

Following this logic, here a BIAL code as an alternative for mod:

year=2016;
divisor=4;
var txt = "";

txt = Convert.floatToString(year/divisor+1.1*0);
var integer = Convert.stringToInt(txt.substring(0,txt.indexOf(".")));


APPLICATION.alert(year-(divisor*(integer))+" ");

Best regards,

Victor

PS: This works well for me having the decimal separator defined as dot, you migth want to take care for commas as well in a productive environment.

TammyPowlas
Active Contributor
0 Kudos

Please look at this blog

and the code attached to the blog where he has a leap year example

If that doesn't work would you please provide more context/information?