简体   繁体   English

BigDecimal根据语言环境呈现小数点?

[英]BigDecimal rendering the decimal point according to locale?

related to another issue I found out that: if I want to display BigDecimal.ZERO in JSF with 2 fraction digits, then I have to hardcode the rounding in my backing bean. 与另一个问题有关,我发现:如果我想在JSF中用2个小数位显示BigDecimal.ZERO,那么我必须在后备bean中对舍入进行硬编码。 Because numberConverter does not work on the constant. 因为numberConverter在常量上不起作用。

BigDecimal.ZERO.SetScale(2, RoundingMode.HALF_UP); //this works and displays: "0.00"

Unfortunately I cannot use locale-dependent displaying the decimal point with that! 不幸的是,我不能使用与语言环境相关的显示小数点! I even cannot change the fractions with min/maxFractionDigits after hardcoding the roundingMode. 在对roundingMode进行硬编码之后,我什至无法使用min / maxFractionDigits更改分数。 <f:convertNumber pattern="..." has NOT effect on the display. <f:convertNumber pattern="..."对显示无效。

This is a real mess, does someone know how to enforce a pattern when displaying a BigDecimal in JSF (not a String! then of course I could use new DecimalFormat). 这真是一团糟,有人知道在JSF中显示BigDecimal时如何执行模式(不是String!那么我当然可以使用新的DecimalFormat)。

If the actual format of the textis important - say, you're dealing with locale-dependant data - then you're going to need to use a formatter to render it in a specific 'style'. 如果文本的实际格式很重要-例如,您正在处理与语言环境相关的数据-那么您将需要使用格式化程序以特定的“样式”呈现它。 That's the entire purpose of the class. 这是本课程的全部目的。 Using setScale() changes the mathematical precision available to the instance - it doesn't really have any effect (or shouldn't be garuanteed, anyways) about the textual display. 使用setScale()更改实例可用的数学精度-它实际上对文本显示没有任何影响(或者无论如何也不应该保证)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM