CFLOOP with doubles - Coldfusion
-
26-06-2021 - |
سؤال
I am trying to use cfloop to loop form 0.0 to 5.0 but it takes out the decimal point and is looping from 0 to 5 instead.
This is my code
<select name="cweight">
<option value="">---</option>
<cfloop index = "cweight" from = "0.0" to = "5.0">
<option value="#cweightid#">#cweight#</option>
</cfloop>
</select>
I need the loop to go over 0.1,0.2,0.3 until it reaches 5.0.
What should I add to allow me to do this?
المحلول
CF doesn't have "doubles" - numbers have decimal places when they need them.
To do what you want, use NumberFormat with the mask set to 0.0 so that you always get a decimal place.
To increment by 0.1 at a time, simply set the cfloop step attribute.
<cfloop index="cweight" from="0" to="5" step="0.1">
<option value="#cweight#">#NumberFormat( cweight ,'0.0' )#</option>
</cfloop>
لا تنتمي إلى StackOverflow