Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

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

Learn more

View all

Sign in to view all badges

SOLVED

How to use greater than '>' to compare to data values

alik98709228
Level 3
Level 3

Hello,

 

I am using greater than sign '>" to compare two data values and show a value.

For instance, there are two data fields: Men and Women. Men value is '10', and Women value is '5':

 

Men

10

Women

5

 

1: I am using following syntax but its not working:

 

<% if (targetData.Men > targetData.Women) {%>

show this...

 

2: And this is not working either: if (Men - Women) > '30' (%>:

<% if (targetData.Men - targetData.Women) > '30' {%>

show this...

 

Any idea?

 

Thanks!

1 Accepted Solution
Darren_Bowers
Correct answer by
Community Advisor
Community Advisor

Hi @alik98709228 - you don't say what the data type of your attributes are so I'll assume since it isn't working that they are Strings

You can try something like this:

<% if (Number(targetData.Men) > Number(targetData.Women)) { %> ... <% } else {} %>
or 
<% if (parseInt(targetData.Men) - parseInt(targetData.Women)) > 30) { %> ... <% } else {} %>

https://gomakethings.com/converting-strings-to-numbers-with-vanilla-javascript/

Cheers

Darren

View solution in original post

6 Replies
Darren_Bowers
Correct answer by
Community Advisor
Community Advisor

Hi @alik98709228 - you don't say what the data type of your attributes are so I'll assume since it isn't working that they are Strings

You can try something like this:

<% if (Number(targetData.Men) > Number(targetData.Women)) { %> ... <% } else {} %>
or 
<% if (parseInt(targetData.Men) - parseInt(targetData.Women)) > 30) { %> ... <% } else {} %>

https://gomakethings.com/converting-strings-to-numbers-with-vanilla-javascript/

Cheers

Darren

View solution in original post

alik98709228
Level 3
Level 3
The first part is working but the second part is not. Any idea if I am using something incorrect? Syntax wise?
alik98709228
Level 3
Level 3
<% if (parseInt(targetData.Men) - parseInt(targetData.Women)) > 30) {%>
Darren_Bowers
Community Advisor
Community Advisor
I would just use Number() instead of parseInt() in that case. They should do the same as far as the logic goes. Cheers Darren
Sukrity_Wadhwa
Employee
Employee

Hi @alik98709228,

Was the given solution helpful to resolve your query or do you still need more help here? Do let us know.

Thanks!