
- 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:30 AM
Hi Mickey,
I would take a look at this stackoverflow post that describes why you're seeing the issue and some advice on resolving it:
Javascript toFixed Not Rounding - Stack Overflow

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2016 08:37 AM
Thanks, Brad! I bookmarked that link, for future reference.
Mickey

- 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:36 AM
Hey Chuck, there are actually a few situations where that doesn't work in some browsers if this is client side described in the post. If it's server side I think it's fine though.