How to use divide "/" function and between (50 to 100) in an if/else statement | Community
Skip to main content
alik98709228
Level 2
March 14, 2021
Solved

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

  • March 14, 2021
  • 2 replies
  • 1711 views

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!

 

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Darren_Bowers

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

2 replies

Darren_Bowers
Darren_BowersAccepted solution
Level 9
March 14, 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
March 14, 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!

 

Darren_Bowers
Level 9
March 15, 2021
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