Calculation needs to round up, not down

Mickey_Cegon
Tera Expert

I am in need of help to script a calculation where the answer is rounded up, not down. Apparently, in the system we're replacing w/ServiceNow, it was able to add a math statement "round", which would force the calculation to round up whatever is in the calculation.

Previous program has this:

If you are using the (=round)   function it would round up.

=ROUND(5181*0.055,2)

Answer:                          
284.96      

My script is:

var per = u_personal_miles; //this is 5181 in above calc, and is an integer field

var gas = (per *'.055');//comes out to 284.955
gas = gas.toFixed(2);//comes out to 284.95

Any advice would be welcome.

Mickey Cegon

Farm Bureau Financial Services, Inc.

1 ACCEPTED SOLUTION

Chuck Tomasi
Tera Patron

Here's a simple workaround that appears to work:



var per = 5181; //this is 5181 in above calc, and is an integer field


var gas = (per * .055);//comes out to 284.955


gas = Math.round(gas * 100) / 100; // 284.96


View solution in original post

6 REPLIES 6

Thanks, Chuck! I tried that, and it worked fine. It is a server-side script, so I don't think the browser would make a difference on the calculations. The stack overflow article that Brad mentioned talks about that issue.



Mickey


Abhinay Erra
Giga Sage

Here is neat trick to do this. Change your last statement to this


gas=Math.round(gas * 100)/100;