• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Calculating Percentages

New Here ,
Dec 27, 2018 Dec 27, 2018

Copy link to clipboard

Copied

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.

Views

833

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jan 01, 2019 Jan 01, 2019

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

...

Votes

Translate

Translate
Advocate ,
Dec 27, 2018 Dec 27, 2018

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 27, 2018 Dec 27, 2018

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 29, 2018 Dec 29, 2018

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 29, 2018 Dec 29, 2018

Copy link to clipboard

Copied

Thank you, I will try that.

Jason Retherford

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 31, 2018 Dec 31, 2018

Copy link to clipboard

Copied

heading the right path. Now I get "Element PERCENT is undefined in FORM"

<cfset purchasePrice = form.purchase>

<cfset dPayment = form.dPayment>

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

<cfset dpPercentage = form.dpPercent>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 31, 2018 Dec 31, 2018

Copy link to clipboard

Copied

Unless there is an input field named dpPercentage, it won't be in the form scope.  The example BKBK​ presented sets a variable called dpPercentage, not a form field.

V/r,

^ _ ^

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 31, 2018 Dec 31, 2018

Copy link to clipboard

Copied

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>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 31, 2018 Dec 31, 2018

Copy link to clipboard

Copied

ColdFusion is a loosely typed language, which means that by default, 0 = "0" and it also = "false".. so your <cfif baseLoanAmount> is basically saying "If the value of baseLoanAmount is greater than 0", which is false if the value IS zero, so it goes to the cfelse.  purchasePrice times zero divided by 100 is.. zero. 

I'm leaving work, now.  Have a Happy New Year.

V/r,

^ _ ^

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 31, 2018 Dec 31, 2018

Copy link to clipboard

Copied

Thank you; you too!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 31, 2018 Dec 31, 2018

Copy link to clipboard

Copied

Now, I have to go down a set other loan amounts through the rest of the page.  It looks like this may work. I will let you know how I made out.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 01, 2019 Jan 01, 2019

Copy link to clipboard

Copied

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!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 02, 2019 Jan 02, 2019

Copy link to clipboard

Copied

so I could have both of these in there at the same time?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 02, 2019 Jan 02, 2019

Copy link to clipboard

Copied

ok, that worked (thank you!). Now it is causing another issue; since I have the baseLoanAmount set twice, the form is only looking at the first one. how do i get it to pick one or the other when running the form for mLoanAmount?

<!-Calculation for Mortgage Loan Amount->

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 02, 2019 Jan 02, 2019

Copy link to clipboard

Copied

<cfset baseLoanAmount = (purchasePrice - dPayment)>

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

<!---Calculation for Mortgage Loan Amount--->

<cfset mLoanAmount = (baseLoanAmount + upFrontMIP)>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 03, 2019 Jan 03, 2019

Copy link to clipboard

Copied

I called the second one,

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

So use the one or, alternatively, the other.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 03, 2019 Jan 03, 2019

Copy link to clipboard

Copied

that didn't work. it is only taking the first one. I can't get it to take one if there is a down payment entered like (10,000) or percentage like (10). Under Down Payment, I have a row to enter the percentage. I took it back out before I snipped this image.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 03, 2019 Jan 03, 2019

Copy link to clipboard

Copied

RasonJ77  wrote

that didn't work. it is only taking the first one.  I can't get it to take one if there is a down payment entered like (10,000) or percentage like (10).  Under Down Payment, I have a row to enter the percentage. I took it back out before I snipped this image.

This confuses me a bit. To get back to the beginning, a form has been submitted. The definitions

<cfset purchasePrice = form.purchase>

<cfset dPayment = form.dPayment>

are on the action page of the form. These are required fields, so dPayment is available. If you want percentage to also be available here, then you should also include it as a form field.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 06, 2019 Jan 06, 2019

Copy link to clipboard

Copied

it is in the form. I have both in there. Below is what is in the form and the added percentage.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 06, 2019 Jan 06, 2019

Copy link to clipboard

Copied

Then I shall assume the form fields are, respectively, purchase, dPayment and dpPercentage. You could then proceed as follows:

<cfset purchasePrice = form.purchase>

<cfset dPayment = form.dPayment>

<cfset dpPercent = form.dpPercentage>

<cfif isNumeric(dpPercent)><!---If percentage submitted, use it to calculate down-payment --->

     <cfset dPayment = dpPercent*purchasePrice/100>

     <!---Convert to $ amount --->

     <cfset dPayment = LSNumberFormat(dpayment, "$__.__")>

<cfelseif isNumeric(dPayment)><!---If down-payment submitted,  use it to calculate percentage --->

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

</cfif>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 06, 2019 Jan 06, 2019

Copy link to clipboard

Copied

LATEST

You were correct, I was looking at it wrong! it is working as it should now. Thank you so much!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation