gpt4 book ai didi

jsf - h :inputText changing to scientific notation

转载 作者:行者123 更新时间:2023-12-04 00:47:53 25 4
gpt4 key购买 nike

我有一个 h:inputText 控件,我可以在其中输入最多 7 位数字,并将它们转换为十进制表示形式(即输入“9999999”,它将呈现“9999999.0”)。但是,当我输入任何 7 位或更多数字时,它会将其转换为科学记数法(即输入“10000000”并将其呈现为“1.0E7”)。

作为业务需求,我必须以十进制表示而不是科学记数法显示它。有没有人有办法做到这一点?

<h:inputText id="tableQuantityId" 
value="#{fee.tableQuantity}"
disabled="#{!fee.selected}"
rendered="#{editable}"
validator="#{facesValidator.validateQuantity}">
<a4j:support event="onchange" reRender="messages, feePart" ajaxSingle="true"/>
</h:inputText>

编辑:经过进一步调查,它似乎是从“double”类型获取当前格式。 (换句话说,您可以将“10000000”分配给一个 double 并打印它,它会以科学记数法显示给您)。

所以我进入我的 getTableQuantity() 方法并将其更改为:

(双版)

public double getTableQuantity() {
return tableQuantity;
}

(以字符串表示):

public String getTableQuantityFormatted() {

double d = tableQuantity;
NumberFormat formatter = new DecimalFormat("###.#####");

String f = formatter.format(d);
return f;
}

然后我在我的 xhtml 中将“value="#{fee.tableQuantity}"更改为 value="#{fee.tableQuantityFormatted}"

但现在我在 xhtml 页面上收到以下错误:

The quantity value 10000000 is incorrect. /page/feeContent.xhtml @70,58 value="#{fee.tableQuantityFormatted}": Property 'tableQuantityFormatted' not writable on type java.lang.String

最佳答案

<h:inputText 
id="xy"
value="10000000">
<f:convertNumber maxIntegerDigits="10" maxFractionDigits="1" pattern="#########0.0"/>
</h:inputText>

标签f属于:

<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>

以我为例。

关于jsf - h :inputText changing to scientific notation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5072787/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com