Why is my very simple Expression (decimal) not returning a decimal?


#1

I’m trying to use an Expression to return a decimal value (which I’ve done dozens of times in other much more complicated examples) but for some reason webCoRE won’t return anything other than a whole number. Even something so simple as 100/200 returns a value of 0. Any idea what’s going on? Pic attached.


#2

I’d suggest 100.0/200.0. Supply at least one decimal and it will be treated as decimal.


#3

Now that seems silly, doesn’t it? Surely the result of 100/200 isn’t zero. The trouble is that I’m referencing 2 variables that have been assigned elsewhere, so it’s actually A/B. I’ve tried setting A and B as both integer variables and decimal variables, but it doesn’t make a difference. Even if I have the A and B variables set for “decimal” type, when I enter “100.0” as their value they default back to “100”.


#4

I’d cheat and enter it as an Expression :slight_smile: {100.0}


#5

That seems like such a mickey mouse way to hack it together though! My pistons are messy enough as it is…


#6

Dealing with types in groovy is a pain. If you encounter cases like this where integer math is giving unexpected results you can coerce one or both of your variables to decimals in order to fix it, decimal(varA) / varB