
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2016 08:23 AM
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.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2016 08:32 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2016 08:39 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2016 08:33 AM
Here is neat trick to do this. Change your last statement to this
gas=Math.round(gas * 100)/100;