Jump to content
Changes to the Jaspersoft community edition download ×

format currency


Recommended Posts

By: CARLOS ALBERTO SILVA - csilva2001

format currency

2003-05-10 13:03

Please, help me for format a currency value. I want print in this format: R$ 212.347,97

 

Thanks,

Carlos

 

 

 

 

By: Teodor Danciu - teodord

RE: format currency

2003-05-11 04:52

 

Hi,

 

The text fields have an attribute called "pattern".

This is used by the engine to format values in case

the text field expression is of type java.lang.Number

or java.util.Date.

It uses a java.text.DecimalFormat or

a java.text.SimpleDateFormat

object behind the scene and the specified format

pattern.

 

At this moment, the formatting is based on the

system default locale settings.

This should be OK for the majority of cases, since

you are running your Java program in a specific

language environment you probably already have

the system set with the correct locale.

 

So, the first thing you should try is this:

 

<textField pattern="R$#,##0.00">

 

In future versions, maybe we'll enhance the

internationalization by adding the possibility to

specify a Locale for the report.

 

But for the moment, if the locale settings do not

match the settings you want to have in your report

and you cannot modify them for various reasons,

you can still achieve what you want by supplying

yourself the formatter, instead of letting the engine

create a default one.

 

The quickest way to create a formatter inside the

report design is by using a report variable like this:

 

<variable

name="Formatter"

class="java.text.DecimalFormat"

resetType="Report"

calculation="System">

<initialValueExpression>

new java.text.DecimalFormat(

"R$#,##0.00",

new java.text.DecimalFormatSymbols(Locale.FRENCH)

)

</initialValueExpression>

</variable>

 

The text field expression becomes:

 

<textFieldExpression class="java.lang.String">

$V{Formatter}.format($F{MyDoubleField}.doubleValue())

</textFieldExpression>

 

I hope this helps.

Teodor

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...