I have 3 fields as below;

- overtime_total (field type: float)
- gross_total (field type: float) 0/-
- overtime_percent (field type: float)

The value of “overtime_percent” field is calculated as **(overtime_total / gross_total * 100)**

I have written the following custom script to achieve this:

```
frappe.ui.form.on("Charges", "overtime_total", function(frm) {
frm.set_value("overtime_percent", flt(frm.doc.overtime_total) / flt(frm.doc.gross_total) * 100);
});
frappe.ui.form.on("Charges", "gross_total", function(frm) {
frm.set_value("overtime_percent", flt(frm.doc.overtime_total) / flt(frm.doc.gross_total) * 100);
});
```

Now the problem arises for 2 cases as below:

**Case 1:** When value of “gross_total” field is 0, then the value of “overtime_percent” is shown as INFINITY (obviously since its a divide by 0), but for this case I want to set the value of “overtime_percent” as simply **0 instead of INFINITY**

**Case 2:** When value of “gross_total” field is negative (-10, -25, etc.) then the value of “overtime_percent” is shown as a negative value, but I want to show the value of “overtime_percent” to always show as a positive number.

For eg.:

overtime_total: 50

gross_total: -200

overtime_percent: -25 (this should be shown as **25 instead of -25**)

Any help is appreciated. Thanks