jasper reports - How do I set number format with custom Grouping and Decimal separators -


for example: have 9999.99 , want display 9.999,99 in report.

i try set custom pattern #.##0,00;-#.##0,00 not working

my textfield:

enter image description here

the work of pattern depends on locale settings. grouping , decimal separators defined in locale.

if want free of regional (locale) settings can use scriptlet:

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);     } } 

this scriptlet allows set pattern, custom grouping , decimal separators.

the jrxml file:

<?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 cost 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 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> 

i've set grouping , decimal separators , pattern (#,##0.00;#,##0.00-).

the result be:

enter image description here


note

don't forget add class (jar) sriptlet classpath.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -