Java 无法在<;p:inputNumber/>;素数面的控制
我使用一个控件获取作为印度货币的输入。我期望的格式是Java 无法在<;p:inputNumber/>;素数面的控制,java,jsf,primefaces,jsf-2.2,Java,Jsf,Primefaces,Jsf 2.2,我使用一个控件获取作为印度货币的输入。我期望的格式是###########,但我无法同时使用locale='hi_IN'或pattern='#####,#####。控件的值为double类型 如果我将区域设置更改为“”中的“hi_”,则数字将以Devanagari格式显示,默认为千位分隔符格式(#、#、#、#)。 有没有办法实现INR格式?基于我用com.ibm.icu.text.DecimalFormat制作了一个转换器: package my.converter; import java.
###########
,但我无法同时使用locale='hi_IN'
或pattern='#####,#####
。控件的值为double类型
如果我将区域设置更改为“”中的“hi_”,则数字将以Devanagari格式显示,默认为千位分隔符格式(#、#、#、#)。
有没有办法实现INR格式?基于我用com.ibm.icu.text.DecimalFormat
制作了一个转换器:
package my.converter;
import java.math.BigDecimal;
import java.text.ParseException;
import java.util.Locale;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;
import javax.faces.convert.FacesConverter;
import com.ibm.icu.text.DecimalFormat;
@FacesConverter("enhancedDecimalConverter")
public class EnhancedDecimalConverter implements Converter<BigDecimal> {
@Override
public BigDecimal getAsObject(FacesContext context, UIComponent component, String value) {
if (null == value) {
return null;
}
DecimalFormat format = getFormatter();
BigDecimal result;
try {
result = BigDecimal.valueOf(format.parse(value).doubleValue());
} catch (ParseException e) {
throw new ConverterException(e);
}
return result;
}
@Override
public String getAsString(FacesContext context, UIComponent component, BigDecimal value) {
if (null == value) {
return null;
}
DecimalFormat format = getFormatter();
String result = format.format(value);
return result;
}
private DecimalFormat getFormatter() {
return (DecimalFormat) DecimalFormat.getCurrencyInstance(getLocale());
}
private Locale getLocale() {
return FacesContext.getCurrentInstance().getViewRoot().getLocale();
}
}
示例faces config.xml
中的Locale
配置:
<dependency>
<groupId>com.ibm.icu</groupId>
<artifactId>icu4j</artifactId>
<version>64.1</version>
</dependency>
<application>
<locale-config>
<default-locale>hi_IN</default-locale>
</locale-config>
</application>
。如果您使用它,请确保它与您的项目兼容。非常有趣-因此在hi\u中的区域设置中
是十进制分隔符,,
是什么?成百上千的分隔符?也许java专家知道如何在java中处理这种模式-这就是为什么我添加了java
标记。也许我缺少它,但p:inputNumber具有decimalSeparator=“,”MilliandSeparator=“”的属性。请参见展示@Melloware分离器将大小为3的组分开。OP需要将混合尺寸组2和3分开。wie说2500000等于250万,他们说是2500万(一位朋友向我解释)。了解这个术语后,我发现QA:-看起来op需要一个自定义转换器,因为使用标准JavaAPI是不可能的。
<application>
<locale-config>
<default-locale>hi_IN</default-locale>
</locale-config>
</application>