Skip to main content
RasonJ77
Participating Frequently
December 27, 2018
Answered

Calculating Percentages

  • December 27, 2018
  • 20 replies
  • 1973 views

I have a mortgage site that I inherited. I can enter the down payment at a certain dollar value.  The owner wants to add the ability to either enter down payment (currently I have in site) or enter the percentage of a down payment.  Below is where I need to add the code and what was in there to start. 

<tr>

                    <td valign="middle"><div align="right">Down Payment:</div></td>

                    <td valign="middle"><span class="style6"></span></td>

<td valign="middle"><span class="style6">

                      <cfinput name="dPayment" type="text" tabindex="23" size="15" required="yes" message="Please enter the down payment amount."  />

                      <!--- The down payment should be divided by the purchase price to determine the percentage of down payment (DP / PP = DP%) --->

                    </span></td>

                  </tr>

<!--- Entered 12/16/2018 --->

   <tr>

                    <td valign="middle"><div align="right" class="style8">Or Enter</div></td>

                    <td valign="middle"><span class="style6"></span></td>

                    <td valign="middle"><span class="style6"></span></td>

                  </tr>

Need to know how to enter a percentage here. I am not a developer by any stretch of the imagination.  Any help offered would be appreciated.

    This topic has been closed for replies.
    Correct answer BKBK

    That's fixed, now I get this when I put zero in for the dPayment. How to I set this to accept zero?  Again, I apologize for my lack of coding skills.

    <cfif baseLoanAmount>

    <cfset baseLoanAmount = (purchasePrice - dPayment)>

    <cfelse>

    <cfset baseLoanAmount = (purchasePrice * dpPercentage) / 100>

    </cfif>


    RasonJ77  wrote

    That's fixed, now I get this when I put zero in for the dPayment. How to I set this to accept zero?  Again, I apologize for my lack of coding skills.

    <cfif baseLoanAmount>

    <cfset baseLoanAmount = (purchasePrice - dPayment)>

    <cfelse>

    <cfset baseLoanAmount = (purchasePrice * dpPercentage) / 100>

    </cfif>

    For consistency in the calculations, you could change the definition of dpPercentage, as follows

    <cfset purchasePrice = form.purchase>

    <cfset dPayment = form.dPayment>

    <!--- Added 12/31/2018 for percentage --->

    <cfset dpPercentage = (purchasePrice-dPayment)*100/purchasePrice>

    The baseLoanAmount then follows from:

    <!--- Sufficient definition of baseLoanAmount --->

    <cfset baseLoanAmount = purchasePrice - dPayment>

    <!--- Alternative definition of baseLoanAmount --->

    <cfset baseLoanAmount = dpPercentage*purchasePrice/100>

    Hence, when dPayment is zero, baseLoanAmount is the purchasePrice.

    Happy New Year!

    20 replies

    BKBK
    Community Expert
    Community Expert
    December 29, 2018

    From what you've shown us, you could do the following in the action page of the form:

    <cfset dpPercentage=(form.dPayment/form.pPrice)*100>

    I have assumed dPayment and pPrice are input fields.

    RasonJ77
    RasonJ77Author
    Participating Frequently
    December 30, 2018

    Thank you, I will try that.

    Jason Retherford

    EddieLotter
    Inspiring
    December 27, 2018

    rasonj77  wrote

    I am not a developer by any stretch of the imagination.

    This is a problem. Even if you are shown how to add HTML to add a form field that will accept a percentage, what are you going to add to the ColdFusion code that processes the submitted form? There is more to this than adding a bit of HTML.

    I strongly suggest you hire a programmer.

    RasonJ77
    RasonJ77Author
    Participating Frequently
    December 27, 2018

    I know. I told the owner this in the beginning, but he thought I could do this since I know enough to be dangerous when writing code.

    I do have all the other cfm pages that pulls everything together; and I have been able to figure things out in the past, but this one has me stumped.