# Always returns 0

**URL:** <https://forum.inductiveautomation.com/t/always-returns-0/72776>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [April 21, 2023, 6:12pm UTC](https://forum.inductiveautomation.com/t/always-returns-0/72776 "2023-04-21T18:12:06Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thomas\_Salisbury](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/thomas_salisbury/32/62046_2.png) [@Thomas\_Salisbury](https://forum.inductiveautomation.com/u/Thomas_Salisbury)\
**Post date:** [April 21, 2023, 6:12pm UTC](https://forum.inductiveautomation.com/t/always-returns-0/72776/1 "2023-04-21T18:12:06Z")

</div>

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.

```auto
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)

```

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [April 21, 2023, 6:17pm UTC](https://forum.inductiveautomation.com/t/always-returns-0/72776/2 "2023-04-21T18:17:22Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Thomas\_Salisbury](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/thomas_salisbury/32/62046_2.png) [@Thomas\_Salisbury](https://forum.inductiveautomation.com/u/Thomas_Salisbury)\
**Post date:** [April 21, 2023, 6:18pm UTC](https://forum.inductiveautomation.com/t/always-returns-0/72776/3 "2023-04-21T18:18:27Z")

</div>

i = 53  
pmTotal = 57

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

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [April 21, 2023, 6:19pm UTC](https://forum.inductiveautomation.com/t/always-returns-0/72776/4 "2023-04-21T18:19:50Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [April 21, 2023, 6:21pm UTC](https://forum.inductiveautomation.com/t/always-returns-0/72776/5 "2023-04-21T18:21:33Z")

</div>

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

```auto
i = 0.0

```

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [April 21, 2023, 6:22pm UTC](https://forum.inductiveautomation.com/t/always-returns-0/72776/6 "2023-04-21T18:22:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Thomas\_Salisbury](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/thomas_salisbury/32/62046_2.png) [@Thomas\_Salisbury](https://forum.inductiveautomation.com/u/Thomas_Salisbury)\
**Post date:** [April 21, 2023, 6:23pm UTC](https://forum.inductiveautomation.com/t/always-returns-0/72776/7 "2023-04-21T18:23:27Z")

</div>

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