InputNumber formats input fields with numeric Strings. It supports currency symbols, minimum and maximum value, negative numbers, and a lot of round methods.
<div class="card">
<h:form>
<div class="ui-fluid formgrid grid">
<div class="field col-12 md:col-4">
<p:outputLabel for="input1" value="No Configuration"/>
<p:inputNumber id="input1" value="#{inputNumberView.input1}" modifyValueOnWheel="false" />
</div>
<div class="field col-12 md:col-4">
<p:outputLabel for="input2" value="Currency"/>
<p:inputNumber id="input2" value="#{inputNumberView.input2}" symbol=" CHF"
symbolPosition="s" decimalSeparator="," thousandSeparator="." />
</div>
<div class="field col-12 md:col-4">
<p:outputLabel for="input3" value="Min-Max"/>
<p:inputNumber id="input3" value="#{inputNumberView.input3}" minValue="-1000.999"
maxValue="1000" decimalPlaces="3" />
</div>
<div class="field col-12 md:col-4">
<p:outputLabel for="input4" value="Custom Decimals"/>
<p:inputNumber id="input4" value="#{inputNumberView.input4}" decimalPlaces="6" />
</div>
<div class="field col-12 md:col-4">
<p:outputLabel for="input5" value="Empty Display - Blank"/>
<p:inputNumber id="input5" value="#{inputNumberView.input5}" symbol="%"
symbolPosition="s" required="true" emptyValue="empty" />
</div>
<div class="field col-12 md:col-4">
<p:outputLabel for="input6" value="Empty Display - Zero"/>
<p:inputNumber id="input6" value="#{inputNumberView.input6}" symbol="%"
symbolPosition="s" emptyValue="zero" />
</div>
<div class="field col-12 md:col-4">
<p:outputLabel for="input7" value="Empty Display - Symbol"/>
<p:inputNumber id="input7" value="#{inputNumberView.input7}" symbol="%"
symbolPosition="s" emptyValue="always" />
</div>
<div class="field col-12 md:col-4">
<p:outputLabel for="input8" value="Big Decimal"/>
<p:inputNumber id="input8" value="#{inputNumberView.input8}" decimalPlaces="15" />
</div>
<div class="field col-12 md:col-4">
<p:outputLabel for="input9" value="Positive"/>
<p:inputNumber id="input9" value="#{inputNumberView.input9}" minValue="1" decimalPlaces="0" />
</div>
</div>
</h:form>
</div>
@Named
@ViewScoped
public class InputNumberView implements Serializable {
private Double input1 = Double.valueOf(0);
private Double input2 = Double.valueOf(0);
private Double input3 = Double.valueOf(0);
private Double input4 = Double.valueOf(0);
private Double input5 = Double.valueOf(0);
private Double input6 = Double.valueOf(0);
private Double input7 = null;
private BigDecimal input8 = BigDecimal.valueOf(0);
private Double input9 = null;
public InputNumberView() {
input1 = 0d;
input2 = 0d;
input3 = 0d;
input4 = 0d;
input5 = 251.31;
input6 = 60d;
input8 = new BigDecimal("1234.000000001");
input9 = 0d;
}
public Double getInput1() {
return input1;
}
public void setInput1(Double input1) {
this.input1 = input1;
}
public Double getInput2() {
return input2;
}
public void setInput2(Double input2) {
this.input2 = input2;
}
public Double getInput3() {
return input3;
}
public void setInput3(Double input3) {
this.input3 = input3;
}
public Double getInput4() {
return input4;
}
public void setInput4(Double input4) {
this.input4 = input4;
}
public Double getInput5() {
return input5;
}
public void setInput5(Double input5) {
this.input5 = input5;
}
public Double getInput6() {
return input6;
}
public void setInput6(Double input6) {
this.input6 = input6;
}
public Double getInput7() {
return input7;
}
public void setInput7(Double input7) {
this.input7 = input7;
}
public BigDecimal getInput8() {
return input8;
}
public void setInput8(BigDecimal input8) {
this.input8 = input8;
}
public Double getInput9() {
return input9;
}
public void setInput9(Double input9) {
this.input9 = input9;
}
}