How do I format a number as 2.564.894.621 in JasperSoft Studio?

喜你入骨 提交于 2020-12-05 11:42:13

问题


I need to print some big values. A value looks like this

2564894621

now I want to format the float value to this:

2.564.894.621

I am using Jaspersoft Studio to develop my jasper report.


回答1:


The best way to format in jasper report is to use the pattern attribute on the textField tag. This will keep correct class (Number), when exporting to for example excel, excel can identify it as number and will also apply same pattern.

Properties >> TextField >> Pattern

Either you know the correct pattern or you use the IDE to help you generate it

jrxml result

<textField pattern="#,##0">
   <reportElement x="0" y="0" width="200" height="25" uuid="ee49d149-394b-4ac6-a0a2-6d207b0c8d89"/>
   <textElement>
      <font fontName="DejaVu Serif" size="14"/>
    </textElement>
    <textFieldExpression><![CDATA[$F{myNumber}]]></textFieldExpression>
</textField>

And exporting with a Locale that uses . as grouping separator it will display

if your result is with the grouping separator , this does not depend on the pattern but simply your locale see this: How to invert the comma and dot when number formatting

In JasperSoft Studio the locale used during preview can be set in

Window>>Preferences>>Report Execution: Locale

Note: expression like

<textFieldExpression><![CDATA[new DecimalFormat("#,##0").format($F{myNumber})]]></textFieldExpression>

can be used as well but its better to avoid since the export manager will treat this as text only



来源:https://stackoverflow.com/questions/35312071/how-do-i-format-a-number-as-2-564-894-621-in-jaspersoft-studio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!