如何在iReport中用逗号替换点?

时间:2016-04-14 10:50:48

标签: java jasper-reports

首先,iReport需要这个问题。 我必须用逗号替换点符号。我的问题是我们的数据库中的字段类型是BigDecimal,因此不存在任何替换方法。 所以我将类型更改为String,但后来我收到了这条消息:

it.businesslogic.ireport.gui.logpane.ProblemItem@820dc5 The type java.lang.CharSequence cannot be resolved. It is indirectly referenced from required .class files

我的代码如下:

new String($F{gewicht}.toString()).replace(".",",")

我该怎么办?

3 个答案:

答案 0 :(得分:1)

尝试输入以下内容作为文本表达式:

$F{gewicht}.toString().replace(".",",")

如果这不起作用,一种替代方法是处理Java层中的格式,例如

BigDecimal bd = new BigDecimal(1.2345);
NumberFormat nf = NumberFormat.getNumberInstance(Locale.GERMAN);
DecimalFormat df = (DecimalFormat)nf;
String gewicht = df.format(bd);

在这里,我使用了欧洲德语语言环境,其中小数点和逗号与美国和其他地方的角色相反。你可能想要处理逗号和小数点。

答案 1 :(得分:1)

绕过问题:无法解析java.lang.CharSequence类型。它是从所需的.class文件间接引用的

你可以设置一个新的DecimalFormat: 新的DecimalFormat("#,## 0.00€",新的DecimalFormatSymbols(Locale.GERMANY))。format(Double.parseDouble($ F {gewicht}))

谢谢@hering

答案 2 :(得分:0)

您可以使用文本字段模式:

<textField pattern="#,##0.00 €">

这将为您提供德语格式。在这种情况下,这是€值,但你可以跳过€并添加更多的descimals如果需要:

<textField pattern="#,####0.0000">

另一种方法是:

new DecimalFormat("#,##0.00 €", new DecimalFormatSymbols(Locale.GERMANY)). format(Double.parseDouble($F{gewicht}))

相关问题