Expand my Community achievements bar.

Pleas help with rounding decimal field

Avatar

Level 1

I have a totals field that is summing several fields. I wish to have this totals field provide a rounded sum. I've tried setting the trailing digits to 0 but it will not round up, only round down. I have a display pattern for the field of num{($z,zzz,zz9.99)} . Example 162.59 is displaying 162.00 in total field instead of 163.00. Is there something I'm missing or am I missunderstanding how a decimal field works?

code in "calculate" event:

var test=xfa.form.topmostSubform.personnel_page.person_1.salary_cost1.rawValue+
xfa.form.topmostSubform.personnel_page.person_2.salary_cost2.rawValue+
xfa.form.topmostSubform.personnel_page.person_3.salary_cost3.rawValue+
xfa.form.topmostSubform.personnel_page.person_4.salary_cost4.rawValue+
xfa.form.topmostSubform.personnel_page.person_5.salary_cost5.rawValue+
xfa.form.topmostSubform.personnel_page.person_6.salary_cost6.rawValue+
xfa.form.topmostSubform.personnel_page.person_7.salary_cost7.rawValue+
xfa.form.topmostSubform.personnel_page.person_8.salary_cost8.rawValue+
xfa.form.topmostSubform.personnel_page.person_9.salary_cost9.rawValue+
xfa.form.topmostSubform.personnel_page.person_10.salary_cost10.rawValue;
//this rounds the value upon exit of field
var result = MATH.round(test.value);
this.value = result;

1 Reply

Avatar

Level 10

In FormCalc you have a function which do just what you are looking for..

Ceil(162.59)

Put it in a messageBox and see the output..

form1.#subform[0].Button1::click - (FormCalc, client)

$host.messageBox(Ceil(162.59));

OR

You can use the Ceil function of the MATH object in Java Script.

form1.#subform[0].Button1::click - (JavaScript, client)

xfa.host.messageBox("" + Math.ceil(162.59));

Thanks

Srini