Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Oddity: Subtracting .5

Status
Not open for further replies.

webmigit

Programmer
Aug 3, 2001
2,027
US
When you're coding against a deadline, you find the way to make something work and work securely, there's no time to play with other ways to accomplish the same things... Now here's the question...

I wanted to subtract half of an amount from a database:

Code:
#Evaluate(sAmount - .5)#
doesn't work and I don't understand why... is there any way to subtract .5.

Never fear though! Its a bit longer but it does work.. the length is the whole reason I ask this question but...

Code:
#Evaluate(sAmount - (1 / 2))#
does work perfectly..

Anyone do it diffrently... maybe a few less characters?

Tony
 
What is the result that you get? What do you mean by it doesn't work?

What version of CF? Just tried it on MX and it works fine -- you don't need Evaluate by the way.
 
What do you mean by "half of an amount"? Do you mean you want the result to be half of the original number?

Try something like:

Code:
<cfset fullme = 100>
<cfset halfofme = fullme * 0.5>

<cfoutput>#halfofme#</cfoutput>
<!--- should output &quot;50&quot; --->

You can use .5 ... but you have to put 0 in front of it.
Though what your code seems to be wanting to do is:

Code:
<cfset fullme = 100>
<cfset halfofme = fullme - 0.5>

<cfoutput>#halfofme#</cfoutput>
<!--- should output &quot;99.5&quot; --->

Not sure which is desired.
 
Oops I meant to say half of one.. sorry was in a hurry earlier and thanks cstein.. I feel kinda stupid for overlooking that, I was just in a hurry for a method that worked.. haha... 0.5 rather than .5.. lol

Tony
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top