Level 1

0% to

Level 2

Tip /

to gain points, level up, and earn exciting badges like the new
Mission!

View all

## How to use divide "/" function and between (50 to 100) in an if/else statement

alik98709228
Level 2

Likes

3 likes

Total Posts

27 posts

0 solutions
View profile

alik98709228
Level 2

Likes

3 likes

Total Posts

27 posts

0 solutions
View profile
alik98709228
Level 2

13-03-2021

Hello,

In my list, there are two columns, Men and Women. Men value is '10', Women value is '5'.

I wan to convert following formula to use in an if else statement:

if (Men - Women) / Men == '50' to '100' then show this...

I am using following but its not working:

<% if (Number(targetData.Men) - Number(targetData.Women)) / Number(targetData.Men) =='50' to'100" )  { show this}

else { show this} %>

Any idea how to edit this statement to make it work?

Thanks!

#### Accepted Solutions (1)

Darren_Bowers
MVP

Likes

78 likes

Total Posts

263 posts

85 solutions
View profile

Darren_Bowers
MVP

Likes

78 likes

Total Posts

263 posts

85 solutions
View profile
Darren_Bowers
MVP

14-03-2021

Hi @alik98709228 - you can try something like this:

``<% if ( ((Number(targetData.Men) - Number(targetData.Women)) / Number(targetData.Men)) >= 50 && ((Number(targetData.Men) - Number(targetData.Women)) / Number(targetData.Men)) <= 100 )  {...} else {...} %>``

Cheers

Darren

alik98709228
Level 2

Likes

3 likes

Total Posts

27 posts

0 solutions
View profile

alik98709228
Level 2

Likes

3 likes

Total Posts

27 posts

0 solutions
View profile
alik98709228
Level 2

14-03-2021

Hi Darren,

I tried but I am keep getting syntax error:

<% if ( ((Number(targetData.Men) - Number(targetData.Women)) / Number(targetData.Men)) >= 50 && ((Number(targetData.Men) - Number(targetData.Women)) / Number(targetData.Men)) <= 100 ) {...} else {...} %>

Do you think 50 and 100 should be within quotation marks like '50' and '100'?

And there should be "else if" not just "else"?

Let me know.

Thanks!

@alik98709228 If the return of ((Number(targetData.Men) - Number(targetData.Women)) / Number(targetData.Men)) is a string then use the quotation marks. If the return data type is integer then keep it without quotations marks. it should be just If and else. Else if is required when you have multiple conditions
Since you are converting the targetData attributes to numbers using Number() to perform a calculation (Men-Women)/Men then you need to compare the result of that to a number. If you add the quotes in, it will try to compare a number to a string. You also dont want an if else() statement in the since you only have two options (i.e. between 50 and 100 or everything else). To debug things like this, you can output the calculation part to the email as plain text and see what value you are getting. Things like targetData.Men = 0 will give you a divide by zero error so you might need to sanitise the results. Hope this helps. Darren
Hi Darren and Manoj, It worked. Thanks for your feedback!!!