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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

BC or Financial Math

Status
Not open for further replies.

fiber0pti

ISP
Nov 22, 2000
96
US
Does anyone know anything about coldfusion and BC Math.
Example: Add 0.01 to a 0. loop that 100 times and then subtract 1.0 from it. Notice all the extra numbers after the number? It should be 0.0 but its not.. its like 0.0000000006432423. any Suggestions?
 
Try using the Val() function

=== START CODE EXAMPLE ===
<CFSCRIPT>

c = 0;
for(i=1; i LTE 100; i=i+1){
c = c + 0.01;
}

[COLOR=666666]// Equals; 6.66133814775E-016[/color]
c1 = c - 1.0;
WriteOutput(c1 & &quot;<BR>&quot;);

[COLOR=666666]// Equals; 0[/color]
c2 = Val(c) - 1.0;
WriteOutput(c2 & &quot;<BR>&quot;);

</CFSCRIPT>
=== END CODE EXAMPLE === - tleish
 
That actually works. Although I do not know javascript. Is there a way to do it within coldfusion?
 
That is ColdFusion, using <CFSCRIPT> (ColdFusion Script).

The other way to do it using all tags is:

<CFSET c = 0>
<CFLOOP FROM=&quot;1&quot; TO=&quot;100&quot; INDEX=&quot;i&quot;>
<CFSET c = c + 0.01>
</CFLOOP>

[COLOR=666666]<!--- Equals: 6.66133814775E-016 --->[/color]
<CFSET c1 = c - 1.0>
<CFOUTPUT>#VARIABLES.c1#</CFOUTPUT>

[COLOR=666666]<!--- Equals: 0 --->[/color]
<CFSET c2 = Val(c) - 1.0>
<CFOUTPUT>#VARIABLES.c2#</CFOUTPUT> - tleish
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top