Help with comparing decimal values from items

I just want to compare two decimal values in if statement

if( (item.state as DecimalType) < (min.state as DecimalType) ){
  
}

vscode gives me error message

Ambiguous binary operation.
The operator declarations
	operator_lessThan(Number, Number) in NumberExtensions and
	operator_lessThan(Type, Number) in NumberExtensions
both match.(org.eclipse.xtext.xbase.validation.IssueCodes.ambiguous_feature_call)

Try item.state as Number

1 Like

In general, don’t cast stuff to types in DSL rules unless you have to. Let the interpreter sort it out.

Having said that, you do have to type for this because .state might be ON/OFF or whatever. But use the “native” rules type, as Number

Fuller explanation is further down in here.

Community search tool is quite good.

The next surprise you might run into with comparisons is Quantity Type Items, with units embedded.

1 Like

Thanks @Charley and @rossko57