回答
工作模式取决于区域设置设置。 分组和十进制分隔符定义在区域设置。
如果你想成为自由区域(区域设置)设置,您可以使用这个小脚本的:
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
- 1. 如何格式化数字来定义数千个分隔符?
- 2. 如何格式化数字,没有分组分隔符
- 3. asp.net mvc设置数字格式默认小数千分隔符
- 4. 千位分隔符的数字格式
- 5. Matplotlib数字分组(小数分隔符)
- 6. 如何将数字格式设置为特定数量的小数位数和逗号分隔符?
- 7. 如何将字符串和/或数字分隔到数组中?
- 8. WPF字符串格式使用自定义分隔
- 9. 格式化数字/字符串与小数点分隔符
- 10. (C++)在由空格分隔的字符串中分隔数字
- 11. 格式的数字串逗号分隔符为印度数字
- 12. 如何用连字符分隔数字
- 13. 如何拆分包含分隔符和转义分隔符的字符串?
- 14. 格式字符串数组到自定义字符串
- 15. 如何设置ListFragment自定义布局的分隔符(为空)
- 16. 分隔字符串作为数组vba的分隔符?
- 17. gnuplot的错误:“坏格式字符”,尽管“设置数据文件分隔符”
- 18. 字符串分割到字符串数组没有分隔符
- 19. 分隔数字数组C#
- 20. Elasticsearch自定义分析器与Ngram和没有字母分隔符连字符
- 21. 如何将awk分隔符设置为字符串或字符?
- 22. 逗号分隔的字符串数组
- 23. 自定义Rails URL参数分隔符?
- 24. 如何在PIG中设置自定义分隔符
- 25. 如何设置自定义千位分隔符?
- 26. 如何设置逗号分隔。字符串作为参数?
- 27. 如何将UITableViewCell分隔符更改为自定义分隔符?
- 28. 如何在NetworkStream字节数组中放置分隔符?
- 29. 将字符串拆分为数组并将分隔符设置为键
- 30. 字数与自定义分隔符(|)使用猪
你可以发布字段和* 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