EasyCFM.COM ColdFusion Forums / Coding Help! / Math Function help.

   Reply to Discussion | New Discussion << previous || next >> 
Posted By Discussion Topic: Math Function help.

book mark this topic Printer-friendly Version  send this discussion to a friend  new posts last

SouthLand
09-28-2007 @ 10:48 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Junior Member
Posts: 105
Joined: Jun 2004

Hello,

I have a project that needs to have a little math done. A url will have a number in it say adue=36.57
that will be passed to me. If the number is from 1 to 50 I need to add 3 to the 36.57 making the total 39.57

If the number is 50.01 to 100.00 I need to add 5
If the number is 100.01 to 200.00 I need to add 8

after the initial number gets to 100 I need to add 3 to every hundred after that.

so if the number was 357.08 the added amount would be 14 making.

If you could help with an example or a tutorial that would be great.

Thank you.



kicker
09-28-2007 @ 1:35 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Moderator
Posts: 717
Joined: Oct 2004

I am not sure what the largest possible amount would be so I came up with this that will work in most scenarios.

  

< cfscript>
     if(url.adue LT 50) {
          total = url.adue + 3;
     }else if (url.adue GT 50 and url.adue LT 100) {
          total = url.adue + 5;
     }else if(url.adue GT 100 and url.adue LT 200) {
          total = url.adue + 8;
     }else if(url.adue GT 200 and url.adue LT 300) {
          total = url.adue + 11;
     }else if(url.adue GT 300 and url.adue LT 400) {
          total = url.adue + 14;
     }else {
          total = "Sorry not within my specs.";
     }
</ cfscript>
< cfoutput>#total#</ cfoutput>

If you are considering doing it into the tens of thousands it wouldn't be the best solution. And I am not saying that this is the best solution either but it does the job.

Craig
Clearcg.com

This message was edited by kicker on 9-28-07 @ 1:43 PM

tmbrown
09-28-2007 @ 1:39 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Junior Member
Posts: 143
Joined: Aug 2007

this might work. i only know math functions for VB and C++

<cfset NumOne = "FORM.Number1">
<cfset NumTwo = "FORM.Number2">
<cfset Sum = NumOne + NumTwo>
<cfif Sum GTE "50.1">
  Sum + 5.0
</cfif>
<cfif Sum LTE "100.0">
  Sum + 5.0
</cfif>
<cfelseif Sum GTE "100.01">
  Sum + 8.0
</cfif>
<cfelseif Sum LTE "200.0">
  Sum + 8.0
</cfif>


I'll have to figure out the rest in a bit.  Hope this helps.  Like I said, I don't really know CF Decision Operators/Math Functions.  Plus my math skills suck.  So yeah if it's wrong please don't get mad.




T-Rav

SouthLand
09-28-2007 @ 2:46 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Junior Member
Posts: 105
Joined: Jun 2004

kicker & tmbrown,

Yea, I know how I could have done it by going up 100 at a time, problem is that this number can go up to around 100,000 most will be less than 5,000 but some are higher and I dont want to do each increment.

Looking for a way to get done no matter how high the number really.

Thanks for the help.

tmbrown
09-28-2007 @ 4:43 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Junior Member
Posts: 143
Joined: Aug 2007

I'm not exactly sure on the exact code, but I do know you could loop it and set the variable as the number you want to go up to and set it to loop no higher than that number but every increment of 50 or 100 or what not inbetween 50 and 100,000.  I'll play with it and see what I can come up with for you, Kicker would probably be better at it than me though.

T-Rav

kicker
09-28-2007 @ 4:46 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Moderator
Posts: 717
Joined: Oct 2004

Are the numbers above the exact numbers you are looking for as far as increment? 3,5,8,11,14,17,20,etc?

Craig
Clearcg.com

tmbrown
09-28-2007 @ 5:46 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Junior Member
Posts: 143
Joined: Aug 2007

Haven't really had a chance to peel it apart but i found this snippet on Adobe's site

The following example increments CountVar from 1 to 5.

<!--- Set the variable CountVar to 0 --->
<cfset CountVar = 0>
<!--- Loop until CountVar = 5 --->
<cfloop condition = "CountVar LESS THAN OR EQUAL TO 5">
   <cfset CountVar = CountVar + 1>
   The loop index is <cfoutput>#CountVar#</cfoutput>.<br>
</cfloop>

The output of this loop is as follows:

The loop index is 1.
The loop index is 2.
The loop index is 3.
The loop index is 4.
The loop index is 5.

Link:  [url]=http://livedocs.adobe.com/coldfusion/6.1/htmldocs/tags-p78.htm#wp1101126]http://livedocs.adobe.com/coldfusion/6.1/htmldocs/tags-p78.htm#wp1101126[/url]

Theoretically you could make one loop, but I believe it'd be easier just to make 2 one for 000.00's and another for the 000.01's.

T-Rav

This message was edited by tmbrown on 9-28-07 @ 5:48 PM

Sponsored By...
iOpenSoft, LLC is a Houston, Texas Advanced Technology Studio Specializing in Web Design, Web Development, iPhone App Development and Android App Development.