Skip to main content
Inspiring
June 3, 2015
質問

Can I make number field have decimal places?

  • June 3, 2015
  • 返信数 1.
  • 3744 ビュー

Hi. I have a field in my SQL database that is an integer field. When I try to use this field in my form, it only allows whole numbers to be entered. How can I allow numbers with decimal points to be entered? The field name is called Eng_Hrs. Here's what I have on the Form:

<tr>

<td class="edit" align="left">Engineering Hours:    <input type="text" name="Eng_Hrs" size="12" validate="integer" <!--- required="no" ---> message="You must enter a valid number in the Engineering Hours field"></td>

</tr>

I realize I could make this a text field and it would allow decimal points, but then how could I validate this field to make sure that only whole numbers or numbers with decimal points are entered?

Thanks.

Andy

    このトピックへの返信は締め切られました。

    返信数 1

    Inspiring
    June 3, 2015

    You will need to validate the field relative to the SQL field.

    You can set the SQL field as decimal or numeric (decimal and numeric) which will allow only numbers and then validate against that. Then set the validate to numeric.

    I would recommend not using cfinput though. If you are not using existing code, just stick with html and javascript for validation.

    jamie61880作成者
    Inspiring
    June 3, 2015

    I set the SQL field to be decimal or numeric, but when I try to enter a decimal number like 2.5 directly into the database, it still rounds it up to 3. I think I need to get that working first before I do any validation on the Cold Fusion code. Do you know why it's rounding up to a whole number still? Should't it allow it to be 2.5 if I have it set to be Decimal or Numeric?

    Inspiring
    June 3, 2015

    It depends how you set the data type.

    In SQL Server, as mentioned in the link in my last post, decimal and numeric take arguments.

    So if you wanted a number up to to 10 numbers long and have 2 decimal points then you would set it to numeric(10,2)