My guess is that the issue here is how ColdFusion deals with numbers. It is converting your strings "0.01" and "0.06" into numbers and probably loosing precision at some point. Remember ColdFusion is loosely typed.
ColdFusion does not use explicit types for variables, while Java is strongly typed. However, ColdFusion data does use underlying Java types to represent data.
From Java and ColdFusion data type conversions
I have modified the ColdFusion example on TryCF in an attempt to show my point. I used javacast()
to explicitly define the numbers as floats. Try the new code here.
<cfloop from="#javacast('float','0.01')#"
to="#javacast('float','0.06')#"
index="i"
step="#javacast('float','0.01')#">
i=#i#<br>
</cfloop>
This now outputs the expected six times.
i=0.00999999977648
i=0.019999999553
i=0.0299999993294
i=0.0399999991059
i=0.0499999988824
i=0.0599999986589
You could then add the NumberFormat()
function when outputting these values to get the output you want. Not sure of the precision that you need here. You could just use Duncan's example as well.
<cfloop from="#javacast('float','0.01')#"
to="#javacast('float','0.06')#"
index="i"
step="#javacast('float','0.01')#">
i=#NumberFormat(i,"9.99")#<br>
</cfloop>
Outputs:
i=0.01
i=0.02
i=0.03
i=0.04
i=0.05
i=0.06