回答
工作模式取决于区域设置设置。 分组和十进制分隔符定义在区域设置。
如果你想成为自由区域(区域设置)设置,您可以使用这个小脚本的:
package utils;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.util.Locale;
public class CustomDecimalFormatter {
public static String format(BigDecimal value, String pattern, char decimalSeparator, char groupingSeparator) {
DecimalFormatSymbols otherSymbols = new DecimalFormatSymbols(Locale.getDefault());
otherSymbols.setDecimalSeparator(decimalSeparator);
otherSymbols.setGroupingSeparator(groupingSeparator);
DecimalFormat df = new DecimalFormat(pattern, otherSymbols);
return df.format(value);
}
}
这个小脚本允许设置模式,自定义分组和十进制分离。
的JRXML文件:
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="format_decimal" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<import value="utils.CustomDecimalFormatter"/>
<queryString>
<![CDATA[SELECT id, cost*100 as cost from product]]>
</queryString>
<field name="ID" class="java.lang.Integer"/>
<field name="COST" class="java.math.BigDecimal"/>
<columnHeader>
<band height="50">
<staticText>
<reportElement x="0" y="0" width="154" height="50"/>
<box leftPadding="10">
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement textAlignment="Center">
<font isBold="true"/>
</textElement>
<text><![CDATA[The result of using
classical pattern.
Depends on System locale]]></text>
</staticText>
<staticText>
<reportElement x="154" y="0" width="191" height="50"/>
<box leftPadding="10">
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement textAlignment="Center">
<font isBold="true"/>
</textElement>
<text><![CDATA[The result of using the sriptlet]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="20" splitType="Stretch">
<textField pattern="#,##0.00;#,##0.00-">
<reportElement x="0" y="0" width="154" height="20"/>
<box leftPadding="10">
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement/>
<textFieldExpression class="java.math.BigDecimal"><![CDATA[$F{COST}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="154" y="0" width="191" height="20"/>
<box leftPadding="10">
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[CustomDecimalFormatter.format($F{COST}, "#,##0.00;#,##0.00-", ',', '.')]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>
我已经设置了分组和小数分离器和模式(#,##0.00;#,##0.00-
)。
结果将是:
注意
不要忘了与sriptlet添加类(JAR)到类路径中。
非常感谢!但它在碧玉报告中唯一的显示。当我使用OpenERP插件贾斯珀报告,它仍然显示分隔符是','你能帮我 – 2013-05-16 08:54:30
你可以检查在* OpenERP *运行的服务器上的sriptlet的工作?我的意思是* CustomDecimalFormatter.format *方法的工作 – 2013-05-16 09:09:48
@Alex K你能告诉我如何在我的OpenERP Addons中添加我的Java类文件(CustomDecimalFormatter.java)文件。我想添加到我的自定义模块中。 – 2015-09-28 04:57:54
你可以发布字段和* textField *声明(* jrxml *的片段)吗? – 2013-05-14 09:24:17
你可以看到:http://i.stack.imgur.com/xZySo.png – 2013-05-15 03:15:55
在这种情况下,文本会更好,然后截图......'$ F {out_balance}'字段的类型是什么? – 2013-05-15 06:31:59