Simple Thermostat rule (sensor in ,valve control)

Hi I have a problem with a simple rule for controling a 3 way valve based on the sensor temp.
The script is found on internet but when adapted it throws.

2016-04-27 00:42:34.721 [ERROR] [o.o.c.s.ScriptExecutionThread ] - Error during the execution of rule 'heating water thermostat': Cannot cast org.openhab.core.library.types.DecimalType to void

This must be something with the variable declaration, as it will happen even with just firs 3 lines.

Here is the rule

rule "heating water thermostat"
    when
		Item B_Temperature_Water_Setpoint changed or
		Item B_Temperature_tgS_heating_water changed 
	then
	var Number setpoint = B_Temperature_Water_Setpoint.state as DecimalType
	var Number cur_temp = B_Temperature_tgS_heating_water.state as DecimalType
    val  hysteresis = 0.5
	
		if (cur_temp <= (setpoint - hysteresis)) {
			if (boiler_outb0.state == OFF) {
				sendCommand(boiler_outb1, OFF)
				sendCommand(boiler_outb0, ON)
				}
			}
		else {
			sendCommand(boiler_outb0, OFF)
			}
			
	if (cur_temp >= (setpoint + hysteresis)) {
			if (boiler_outb1.state == OFF) {
				sendCommand(boiler_outb0, OFF)
				sendCommand(boiler_outb1, ON)
				}
			}
		else {
			sendCommand(boiler_outb1, OFF)
			}			
    end

Since you can use a DecimalType as a Number, why not define them as:

var DecimalType setpoint = B_Temperature_Water_Setpoint.state as DecimalType
var DecimalType setpoint = B_Temperature_tgS_heating_water.state as DecimalType

I assume both Items are Number Items and not some other Item type.

that did not help and and I still get the exception.

And yes in the items file both are declared as Numbers

Number B_Temperature_tgS_heating_water "Temp_tgS Floor Heating Water [%.1f C]" <temperature> (TempChart_heating_water,TempChart1,gBasement)  {tinkerforge="uid=tgS"}
Number B_Temperature_Water_Setpoint    "Heating Water Setpoint [%.1f °C]"  <degreesc>  (HeatingSetpoint)

Ok I solved the problem, but I still do not understand why the following code work while the previous one does not

rule "heating water thermostat"
    when
		Item B_Temperature_Water_Setpoint changed or
		Item B_Temperature_tgS_heating_water changed 
	then
	
	var Number cur_temp = B_Temperature_tgS_heating_water.state 
	var Number setpoint = B_Temperature_Water_Setpoint.state 
        val  hysteresis = 0.5
	
	if ((cur_temp).floatValue < ((setpoint).floatValue - hysteresis)) {
			if (boiler_outb0.state == OFF) {
				sendCommand(boiler_outb1, OFF)
				sendCommand(boiler_outb0, ON)
				}
			}
		else {
			sendCommand(boiler_outb0, OFF)
			}
end