-1

I have this jsp input text code:

    <td>
        <input type="text" name="qty" id="qty" size="10" value=<%=quantitySet%>
            class='<%=stkAdjFrm.itemObj.isDecimalItemType()?<???>:<???>%>' 
            onblur="chkZero(this.value,'qty','qtyError','Quantity must not be zero');" />&nbsp;
        <label id="qtyError" for="qtyError" class="errMsg"></label>         
    </td>                       

The class checks whether the value is a decimal or non-decimal. Any idea what to place in condition?

If its decimal it needs to show 6 decimal places, otherwise show no decimal places at all.

Arnold Cristobal
  • 843
  • 2
  • 16
  • 36
  • Define "decimal". `double`? `float`? `BigDecimal`? `"3.12"`? Is a `double` with value `1` a decimal? And if you need to show 6 decimal places, shouldn't you be setting the `value` attribute as such, rather than `class`? – Andreas Dec 22 '15 at 02:33
  • Possible duplicate of [Formatting numbers (decimal places, thousands separators, etc) with CSS](http://stackoverflow.com/questions/8677805/formatting-numbers-decimal-places-thousands-separators-etc-with-css) – Erwin Bolwidt Dec 22 '15 at 02:39
  • Although in the DB all have decimal (numeric (30,12) it only need to show decimal places based on the item as some item does not require decimal. BigDecimal to answer your question on Define Decimal. – Arnold Cristobal Dec 22 '15 at 02:41
  • And why not use `type="number"`? – chrylis -cautiouslyoptimistic- Dec 22 '15 at 02:43

1 Answers1

0
<td>
    <% if (stkAdjFrm.itemObj.isDecimalItemType()) { %>
        <%@ page import="java.text.NumberFormat" %>
        <% NumberFormat nf = NumberFormat.getInstance();
        nf.setMaximumFractionDigits(6);
        nf.setMinimumFractionDigits(6); %>

        <input type="text" name="qty" id="qty" size="10" value=<%=nf.format(0)%>
        onblur="chkZero(this.value,'qty','qtyError','Quantity must not be zero');" />&nbsp;
        <label id="qtyError" for="qtyError" class="errMsg"></label>         

    <% } else { %>  

        <input type="text" name="qty" id="qty" size="10" value=<%=quantitySet%>
        class="kendo-numeric"
        onblur="chkZero(this.value,'qty','qtyError','Quantity must not be zero');" />&nbsp;
        <label id="qtyError" for="qtyError" class="errMsg"></label>         

    <% } %>
</td>                       

Just used NumberFormat and discard the class if decimal places are needed.

Arnold Cristobal
  • 843
  • 2
  • 16
  • 36