Jump to content
We've recently updated our Privacy Statement, available here ×

How To Format Numbers Retrieved From Database


2004 IR Help

Recommended Posts

By: Chalk S. Bareng - chalksb

How To Format Numbers Retrieved From Database

2002-11-06 00:51

Hello!

I am retrieving numbers from the database.

Example: 20, 30, 1.5

But I want the report to display these numbers in currency format.

Example: 20.00, 30.00, 1.50.

Is there a way to do this?

Thank you.

 

 

 

 

By: Giulio Toffoli - gt78

RE: How To Format Numbers Retrieved From Database

2002-11-06 01:06

Yes, you can use the pattern field (over the fieldExpression field).

Examples:

db double: 12345.345

Pattern: 0.00 result: 12345.34

Pattern: #,##0.000 result 12,345.345

 

In your case pattern: 0.00

results: 20.00 30.00 1.50

 

You can use pattern with all numeric types (as integer, double, float...)

 

Giulio

 

 

 

 

By: Chalk S. Bareng - chalksb

RE: How To Format Numbers Retrieved From Database

2002-11-06 22:06

I realized that the numbers I am retrieving are of type VARCHAR from MS SQL SERVER 7.0. Is there a way in iReport I can convert this to double or any numeric format so I can use the pattern field?

Thank you for the help.

 

 

 

 

By: Giulio Toffoli - gt78

RE: How To Format Numbers Retrieved From Database

2002-11-07 00:06

Yes. You can convert your number in Double using this expression for field.

You must change texfield class to java.lang.Double

 

new Double( $F{MYFIELD}.parseDouble() )

 

Now you can use pattern for formatting your number.

 

Pay attention that your string rapresents really end ever a number, otherwise a NumberFormatException will throws filling reports.

 

Giulio

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