# ZeroDivisionError: Float division

**URL:** <https://forum.inductiveautomation.com/t/zerodivisionerror-float-division/38688>\
**Category:** Ignition\
**Created:** [September 15, 2020, 1:01pm UTC](https://forum.inductiveautomation.com/t/zerodivisionerror-float-division/38688 "2020-09-15T13:01:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![felipe2010silva](https://avatars.discourse-cdn.com/v4/letter/f/54ee81/32.png) [@felipe2010silva](https://forum.inductiveautomation.com/u/felipe2010silva)\
**Post date:** [September 15, 2020, 1:01pm UTC](https://forum.inductiveautomation.com/t/zerodivisionerror-float-division/38688/1 "2020-09-15T13:01:45Z")

</div>

Good Morning. my name is Felipe. I created a window to monitor spoilage fluctuation in real time on a Chart component. I wrote the script on the property change in a mes analisys controller component that provides me with a dataset with production data input and output from a machine minute by minute and from these values ​​I created a script to record in the Chart component. However, I have encountered two problems: the first is that sometimes the values ​​of the Chart component do not update to today’s date, as in the attached photo. today is 09/15/2020, but it is registering the spoilage fluctuation of 09/02/2020. but when I look at the dataset of the mes analysis controller, it continues to provide the minute-to-minute values ​​of today. and the second problem is this popup window saying: ZeroDivisionError: Float division. I’ve exhausted my attempts. Below is the script I wrote in the scripting editor \>\> property change of the mes analisys controller:

```auto
if event.propertyName == 'data' and event.source.data is not None:
	dataset = event.source.data
	production1 = 0 //Infeed Machine
	production2 = 0 //Outfeed Machine
	target = 0
	newDataSet = []
	headers = ["Time", "Spoilage", "ideal Spoilage"]
	for row in range(dataset.rowCount):
		date = dataset.getValueAt(row, 0)
		target = 3 + event.source.LineRate
		production1 = production1 + dataset.getValueAt(row, 1)
		production2 = production2 + dataset.getValueAt(row, 2)
		spoilage = (production1-production2)*1.00
		spoilPercent = (spoilage / (production1 * 1.00))*100.00
		newRow = [date,spoilPercent, target]
		newDataSet.append(newRow)
	event.source.parent.getComponent('Chart').Data = system.dataset.toDataSet(headers, newDataSet)

```

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/5/75624b923acb0d2a73e36f53900edee0844a1685.png)

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/6/b/6bec4d567816ef55f4588e9e00f54a9e70edb7f6.png)

Thank you!!!

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [September 15, 2020, 1:17pm UTC](https://forum.inductiveautomation.com/t/zerodivisionerror-float-division/38688/2 "2020-09-15T13:17:45Z")

</div>

I’d say some of your values for production1 are zero. You need to decide what value you want for spoilPercent when that happens:

````auto
if event.propertyName == 'data' and event.source.data is not None:
	dataset = event.source.data
	production1 = 0 //Infeed Machine
	production2 = 0 //Outfeed Machine
	target = 0
	newDataSet = []
	headers = ["Time", "Spoilage", "ideal Spoilage"]
	for row in range(dataset.rowCount):
		date = dataset.getValueAt(row, 0)
		target = 3 + event.source.LineRate
		production1 = production1 + dataset.getValueAt(row, 1)
		production2 = production2 + dataset.getValueAt(row, 2)
		spoilage = (production1-production2)*1.00
		if production1 == 0
			# Set default spoilPercent value if production1 = 0
			spoilPercent = 0
		else:
			spoilPercent = (spoilage / (production1 * 1.00))*100.00
		newRow = [date,spoilPercent, target]
		newDataSet.append(newRow)
	event.source.parent.getComponent('Chart').Data = system.dataset.toDataSet(headers, newDataSet)```
````

---

<div class="post-metadata">

**Author:** ![felipe2010silva](https://avatars.discourse-cdn.com/v4/letter/f/54ee81/32.png) [@felipe2010silva](https://forum.inductiveautomation.com/u/felipe2010silva)\
**Post date:** [September 15, 2020, 2:10pm UTC](https://forum.inductiveautomation.com/t/zerodivisionerror-float-division/38688/3 "2020-09-15T14:10:47Z")

</div>

You are spectacular. worked perfectly. the two errors I mentioned have been resolved. thank you very much!!!
