Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ColdFusion float problems

Im trying to make my program to show two decimals points but it keeps dropping the zero, so if I have 140.00 it shows as 140.0, but if I do 140.15 it will show 140.15. However, for some reason it will always drop the zero. Here is the code I think that needs editing. Any help would be appreciated.

  <cfinput type="Text" name="HourlyRate" 
       value="0.00" 
       required="Yes" 
       validate="float"              
       message="A Default Hourly Rate is required...."
       class="inputText200" size="8">** 

or here

    <input type="text" name="Rate" 
       <cfif #getHourlyForm.Rate# neq ""> value="#getHourlyForm.Rate#"</cfif> />
like image 997
user3182314 Avatar asked Apr 23 '26 09:04

user3182314


1 Answers

The reason is that when you're outputting the content into the "value" you're basically rendering HTML.

What that means is that your numeric values are being "converted" into a string representation when CF is generating the HTML.

Check out the NumberFormat function here which will allow you to tell CF how to output the content rather than it trying to do a "best guess"

<tr colspan="2">
        <td class="tdDescription"> Rate Per Hour </td>
        <td><input type="text" name="Rate" class="inputText350" <cfif getHourlyForm.Rate neq ""> value="#NumberFormat(getHourlyForm.Rate,"9.99")#"</cfif>/></td>
</tr>
like image 56
Shawn E Avatar answered Apr 24 '26 22:04

Shawn E



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!