# Planet Jaspersoft

## Tips : Playing with variables in Jasper Studio to find percentages, to get the two digits after dec…

### Sadakar Pochampalli( JasperSoft BI Suite Tutorials - Sadakar Pochampalli )

Software :
Jasper Design Studio : 6.0.1 Pro
Jasper Server : 6.0.1 Pro

## 1) Calculating Percentage from java.lang.BigDecimal Types

By default all the numeric fields in report takes java.math.BigDecimal & you can not perform arithmetic  operations like division for calculating percentages. (Alternatively you need to work with the methods from BigDecimal class to get % kind of things)

Find percentage :
1) Create a variable  of type java.lang.Double
2) Calculation = Nothing
3) Expression :
\$F{Field1}.doubleValue()/\$F{Filed2}.doubleValue())*100

NOTE : \$F{Field1} and \$F{Filed2} are of java.math.BigDecimal types .
4) Increment type : None
5) Reset group :  If you are creating variables in any data set & using it in table component give your GROUP Name

6) Drag the variable on to the design area of table component.
7) Double click the variable to open it's  expression
a) By default you can see it's expression as \$V{Variable_1}
b) Change the variable expression  to
new DecimalFormat("#.##").format(Double.valueOf(\$V{Variable_1}))+"%"

## 2) Two decimal places after floating point for java.math.BigDecimal type values

\$V{Variable_2}.setScale(2, java.math.RoundingMode.HALF_UP)+"%"
This is on dragged variable. Not in the variable directly. The variable initially \$V{Variable_2}. Double click it to get it's expression editor

Example: 95.83%

NOTE :
a) Create a variable of double type for finding %'s .
i.e.,
Variable Name : VAR_PER_1
Expression :  (a.doubleValue()/b.doubleValue()) *100
Example : 95.834444123

b)  Now convert the above variable to Decimal type by creating a new variable of type Decimal
i.e., Variable Name : VAR_PER_2
BigDecimal.valueOf(\$V{VAR_PER_1})    [Remember it VAR_PER_1]

c) Now get 2 decimal places  by applying   \$V{VAR_PER_2}.setScale(2, java.math.RoundingMode.HALF_UP)+"%"

## 3) Get only  Numeric value as percentage by rounding the decimal places of Double value

Assume you have java.lang.Double type having 45.45 and want to get 46 from it. Then the below expression will help full to you.

Variable_1=45.45                                              of java.lang.Double type
Variable_2= (int) (\$V{Variable_1} + 0.5)        of java.lang.Integer type

[i.e., you need to create another variable of integer type and in its expression type cast the double variable to integer]

There could be another ways to solve the same kind of solutions using java expressions but I hope somehow the above tips help full.

:-) SADAKAR POCHAMPALLI :-)
BI DEVELOPER, HYDERABAD, INDIA.

## Jaspersoft Tech Talks Episode 18: Upgrading JasperReports Server

### jaspersoftbisuite( Jaspersoft Tech Talks )

In this tech talk we will demonstrate the process for upgrading JasperReports Server. This will include a demonstration using both the WAR file installer and the overlay installer packages. For more Jaspersoft Tech Talks, see: http://www.jaspersoft.com/tech-talks

## Connecting Jasper Report Server to MS SQL Server

### supermarianoluna( Jaspersoft Tutorials )

A step by step video how-to on connect MS SQL Server with JasperServer via JDBC

## DomainSecurity

### jaspersoftbisuite( Jaspersoft Tutorials )

Video describing how to add security to domains in order to have row and/or column level security

## BigQuery and Jaspersoft

### jaspersoftbisuite( Jaspersoft Tutorials )

Ad Hoc queries as well as prebuilt reports using BigQuery data

## Jaspersoft WAR File Installation

### jaspersoftbisuite( Jaspersoft Tutorials )

Detailed steps on doing a WAR file install of Jaspersoft using Oracle as the repository database and JBoss as the application server

## User Interface Themes

### jaspersoftbisuite( Jaspersoft Tutorials )

Tutorial on themes

## SSO Integration with LDAP

### jaspersoftbisuite( Jaspersoft Tutorials )

Tutorial on integrating SSO with LDAP

## Connecting Jasper Report Server to MS SQL Server

### supermarianoluna( Jaspersoft Tutorials )

A step by step video how-to on connect MS SQL Server with JasperServer via JDBC

## Deploying a Report to JasperReports Server - Web Client

### bekwam( Jaspersoft Tutorials )

Create a report using Jaspersoft's iReport Designer and upload the report to a centralized JasperReports Server using the web interface

## Pages

Planet Jaspersoft aggregates blog posts from our community. If you would like your blog to be included in the Planet, please follow this help guide. Or just click this link to go straight to your Planet Feeds.

randomness