Jump to content
JasperReports Library 7.0 is now available ×

Numbering format in JR


Recommended Posts

By: BogdanGH - bogdangh

Numbering format in JR

2005-10-19 01:10

Hi,

my problem is that I want to show numbers in a specific format (#0.###) meaning that no matter if the number has digits after "." I want to show 3 digits (eg. 23 -> 23.000; 43.54 -> 43.540; 3.4321 -> 3.432). I have :

 

<textFieldExpression class="java.lang.String"><![CDATA[msg("{0,number,#0.###}",$F{AgreedPrice})]]></textFieldExpression>

 

but if there are no digits after "." it shows nothing. Is there a special format for this kind of case ? Is there support for number format accepted in Java (I use #0.### in Java code) ?

 

Thank you,

Bogdan.

 

 

By: Doug Berkland - berkland

RE: Numbering format in JR

2005-10-19 08:53

I think the format you are looking for is 0.000 instead of 0.###. Specifying the zeros instead of # indicates those decimal places should always be present. Likewise the # at the beginning of #0.### is unneeded. The formats "#0.###" and "0.###" are equivalent since values to left of the decimal are never rounded or truncated.

 

 

By: BogdanGH - bogdangh

RE: Numbering format in JR

2005-10-20 07:05

Thanks, it works. It was my mistake giving the format #0.### as it was #0.000. But now I have another problem. I get the format in from parameter but the formating doesn't work and the value of the parameter is corect:

 

<textFieldExpression class="java.lang.String"><![CDATA[msg("{0,number,1}",$F{AgreedPrice},$P{TextFormat})]]></textFieldExpression>

 

doesn't work and shows the numbers in a normal fashion. If I use :

 

<textFieldExpression class="java.lang.String"><![CDATA[msg("{0,number,0.000}",$F{AgreedPrice})]]></textFieldExpression>

 

it works. The value of the parameter TextFormat is received without problems from the java context :

 

<textFieldExpression class="java.lang.String"><![CDATA[msg("{0,number,1} {1}",$F{AgreedPrice},$P{TextFormat})]]></textFieldExpression>

 

it shows the number in the "classical" format and then shows the format (0.000) so why doesn't it work ?

 

 

By: Lucian Chirita - lucianc

RE: Numbering format in JR

2005-10-21 07:33

Hi

 

Read the java.text.MessageFormat javadoc and you'll understand why it doesn't work.

 

Try this: msg("{0,number," + $P{TextFormat} + "}",$F{AgreedPrice})

 

HTH,

Lucian

 

 

By: BogdanGH - bogdangh

RE: Numbering format in JR

2005-10-24 03:22

Thanks, it works.

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...