[SOLVED] Problems Rounding Number From Distance Calculation

I have been searching to try and figure out this problem and have tried multiple ways of doing it from all my research.
I’m getting this error every time I try and round the calculated distance to 2 decimal places on this example.

Rule 'Justin Distance from home': f != org.eclipse.smarthome.core.library.items.NumberItem
rule "Justin Distance from home"

when
	Item Justin_iPhone_Location changed
then

	Justin_Home_Location.state = new PointType(new DecimalType(00.000000), new DecimalType(-00.000000)) // Change to Yards
	
	
	Justin_Distance_From_Home.postUpdate((Justin_Home_Location.distanceFrom(Justin_iPhone_Location) * 1.09361))
	
	
	logInfo("iCloud.rules",String::format("Justin's Distance from home: %.2f", Justin_Distance_From_Home))
	
end

Any ideas what my problem is ?

Thank You!

I am coming from this rule and trying to shorten the number below…

rule "Justin Distance from home"

when
	Item Justin_iPhone_Location changed
then
	
	
	Justin_Home_Location.state = new PointType(new DecimalType(00.000000), new DecimalType(-00.000000))
	Justin_Distance_From_Home.postUpdate((Justin_Home_Location.distanceFrom(Justin_iPhone_Location) * 1.09361))
	logInfo("iCloud.rules","Justin's distance from home: "+ Justin_Distance_From_Home.state.toString()+ " Yards")
	
	
end
Justin's Distance from home: 38288.8622330804452828 Yards

Hi Justin,

I presume you got the problem resolved in your first post. If not, please post the item definition for “Justin_iPhone_Location” . Regarding your second post, see this thread: Round number to #.#. I think it may be a solution for you

Regards,
Burzin

rule "Justin Distance from home"
when
    Item Justin_iPhone_Location changed
then
    val homeLocation = new PointType(new DecimalType(00.000000), new DecimalType(00.000000))
    val Number distance = Justin_Home_Location.distanceFrom(Justin_iPhone_Location) * 1.09361
    Justin_Distance_From_Home.postUpdate(distance)
    logInfo("iCloud.rules","Justin's distance from home: " + String::format("%.1f", distance.floatValue())+ " Yards")
end

That worked great! Thank You!

One last Question. I have a JavaScript transform function to change the number of meters to miles, tenth of miles, and feet.
How would i get this one to work? It’s just coming up blank after "Justin’s distance from home: "

logInfo("iCloud.rules", "Justin's distance from home: "+ (transform("JS","PrintTime.js",(Justin_Distance_From_Home.toString))))

What is the best way to learn the proper syntax? Is that Java? What topics would this be considered to try and hone in on to better lean this?

Thanks again!

You have two sets of bracket too many
You didn’t use .state

logInfo("iCloud.rules", "Justin's distance from home: "+ transform("JS", "PrintTime.js", Justin_Distance_From_Home.state.toString))

What do the log’s say?

2019-01-16 03:04:38.694 [INFO ] [.smarthome.model.script.iCloud.rules] - Justin's distance from home:

So the transformation just fails silently…
Can you post the transform, please?

The last one you sent works, you were right about I forgot to put in the “.state” and too many brackets. I think maybe I was jumping the gun and looking at the wrong rule refresh before the previous one got unloaded.

Thanks Guys, always speedy responses and helping the little guys out :smiley:

Please tick the solution, thanks