Always returns 0

Hi, I am trying to do some simple math on a returned API.
I know I am not this dumb, but I can not figure out why this always returns 0.

def getWOPercentage():
	client = system.net.httpClient()
	response = client.get("https://api.megamation.com/clm/DL/workorder?&STATUS=CL&ASSIGN_TO=equipment&TYPE=pm&BUILDING_ID=Climatemaster&DATE_DUE=L1")
	i = 0
	for key in response.json['_embedded']['WorkOrder']:
		if (key['completion_date'] <= key['date_due']):
			i = i + 1
	pmTotal = len(response.json['_embedded']['WorkOrder'])

	system.perspective.print((i/pmTotal)*100)

Gotta take it step by step. Check the value for i first.

If you can provide an example of what the api call returns, it would also be helpful.

1 Like

i = 53
pmTotal = 57

I've confirmed those responses already, I just removed them from the code.

well then... Did you try 53/57 ? You might be surprised ;p

hint: you'll need to cast one of them to float.

1 Like

Make zero a float when you define it, that should force floatig point calculations

i = 0.0
1 Like

I'd suggest avoiding floats for as long as possible, and cast one of the operands to float at the end.

1 Like

gotcha. Based on the documentation I thought it did that automagically based on the answer.
I guess I misunderstood that.
Thank you.

1 Like