?
Solved

adding a % to a variable

Posted on 2005-04-04
10
Medium Priority
?
168 Views
Last Modified: 2013-12-24
Hi all,
I have a variable I would like to add a % amount to. For example, <cfset variable = variable + 5%>

How do I go about doing this?

It sounds to me that I first need to take 5% from the variable to get the % needing to be added. Any examples of syntax?

Thanks!


0
Comment
Question by:bluskyGuy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 3
10 Comments
 

Author Comment

by:bluskyGuy
ID: 13703594
I almost got it...however it's not adding a full 5%...

<cfset discount = 5>
<cfset #variables.shipping# = #variables.shipping# + (#discount#/100)>


Original amount: $5.76
Updated amount: $5.81 (should be $6.04)

Any ideas?
0
 
LVL 14

Expert Comment

by:Renante Entera
ID: 13703602
Hi bluskyGuy!

I think this is what you are looking for :

<cfset variable = '#variable#%'>

Hope this helps you.  Just try it.


Goodluck!
eNTRANCE2002 :-)
0
 

Author Comment

by:bluskyGuy
ID: 13703621
Yea no  luck. I receive a 'variable can not be converted to number'...any other ideas?
0
Create the perfect environment for any meeting

You might have a modern environment with all sorts of high-tech equipment, but what makes it worthwhile is how you seamlessly bring together the presentation with audio, video and lighting. The ATEN Control System provides integrated control and system automation.

 
LVL 17

Accepted Solution

by:
Tacobell777 earned 2000 total points
ID: 13703626
<cfset variable = variable  + (variable * 0.05)>

Just try it... ;-)
0
 
LVL 14

Expert Comment

by:Renante Entera
ID: 13703628
Hi bluskyGuy!

Try this :

<cfset variables.shipping = 5.76>
<cfset discount = 5>
<cfset variables.shipping = variables.shipping + (variables.shipping * (discount/100))>

<cfoutput>#variables.shipping#</cfoutput>

This should resolve your problem.


Goodluck!
eNTRANCE2002 :-)
0
 

Author Comment

by:bluskyGuy
ID: 13703631
The code only seems to be adding 5 to the number and not 5%...any ideas on how to add the % part to the equation?
0
 
LVL 17

Expert Comment

by:Tacobell777
ID: 13703637
which answer are you refering to?
0
 
LVL 14

Expert Comment

by:Renante Entera
ID: 13703664
Hi bluskyGuy!

Oh no :((  I'm just too late.  It has been accepted.  I'm expecting this one is splitted.

Anyway, as long as I've come here to help you.


Regards!
eNTRANCE2002 :-)
0
 
LVL 17

Expert Comment

by:Tacobell777
ID: 13704016
Hi eNTRANCE2002 why are you expecting a split?
There was no discount, he needed to add a percentage (maybe tax or shipping costs)..
0
 
LVL 14

Expert Comment

by:Renante Entera
ID: 13704041
Hi Tacobell777!

Actually, I'm just referring to his posted code.

> I almost got it...however it's not adding a full 5%...

> <cfset discount = 5>
> <cfset #variables.shipping# = #variables.shipping# + (#discount#/100)>
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most ColdFusion developers get confused between the CFSet, Duplicate, and Structcopy methods of copying a Structure, especially which one to use when. This Article will explain the differences in the approaches with examples; therefore, after readin…
What You Need to Know when Searching for a Webhost Provider
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses
Course of the Month9 days, 7 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question