Jump to content

Rounding To The Tenth Of A Percent

Recommended Posts

I need help with a calculation that needs to round to the tenth of a percent.


I have an update form with four fields. The fourth field is a calculation based on the numbers entered into 1, 2, and 3.

  1. Management Expenses
  2. Fundraising Expenses
  3. Total Revenue
  4. AFR

My calculation must add management + fundraising and divide that sum by Total Revenue. The result should be input into the AFR field and rounded to the tenth of a percent. 


A few examples of what I need to accomplish:


500 + 500 / 12,000 = 0.0833333 this should be rounded to 8.3%

600 + 500 / 12,500 = 0.088 this should be rounded to 9.0%


The current code that I have used based on the first calculation above only shows 8.0%. I'm new to java so I don't know all the coding that I could be missing here.



One other wrinkle is that I would like the  calculation to strip any symbols. For example if someone enters $1,200  or $1,200.01 I would like to show only 1200 or 1200.01 in the field. I need a way to ensure no symbols are entered into those fields that may render a calculation error. 


 function calculate()
var v_management = parseFloat(document.getElementById("EditRecordManagemenExpenses").value);
var v_fundraising  = parseFloat(document.getElementById("EditRecordFundraisingExpenses").value);
var v_totalrevenue = parseFloat(document.getElementById("EditRecordTotalRevenue").value);
var v_afr  = (([v_management + v_fundraising] / v_totalrevenue)*100);
document.getElementById("EditRecordAFR").value = Math.round(v_afr).toFixed(1) + "%";
 /* On submitting the webform, the function calculate is executed */
Any help would be appreciated!

One other wrinkle is that I would like the  calculation to strip any symbols. For example

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...