Hi, guys. Thanks everybody in this thread for valuable discussion. Hope my case is not very off-topic here. I’ve modified Quality Inspection doctype so that it calculates repair rate with the help of following script:
frappe.ui.form.on("Quality Inspection", "repaired_qty", function(frm, cdt, cdn) {
var d = locals[cdt][cdn];
frappe.model.set_value(cdt, cdn, "repair_rate", d.repaired_qty * 100 / d.inspected_qty);
});
frappe.ui.form.on("Quality Inspection", "inspected_qty", function(frm, cdt, cdn) {
var d = locals[cdt][cdn];
frappe.model.set_value(cdt, cdn, "repair_rate", d.repaired_qty * 100 / d.inspected_qty);
});
Everything works great, but the problem is that I created repair_rate custom field as Data type and resulting numbers are shown like 10.256410256410257.
Is there any way to set precision in custom script? Or the only solution would be to create another custom field with Float type?
frappe.model.set_value(cdt, cdn, "repair_rate", flt(d.repaired_qty * 100 / d.inspected_qty, precision('repair_rate')));
flt(2.xxx, precision('fieldname')) should round it for you