Pattern Expression

How can I use the Pattern and Pattern Expression in the Textfield properties to reduce a java.lang.String value to have two decimal digits?

 

Any assitance would be appreciated .

tholelesego's picture
Joined: Mar 5 2019 - 5:21am
Last seen: 4 years 6 months ago

2 Answers:

There are a bunch of approaches, which depend on your java knowledge. For example, expressions:

A)

String.format("%.2f", new BigDecimal(Double.parseDouble($F{sample})))

B)

new DecimalFormat("0.00").format(new Double($F{sample}))

where $F{sample} is a field from dataset, that contains numbers. I used sample query:

SELECT '25.45060506506456' AS sample

Also, attaching report.

Attachments: 
AttachmentSize
Binary Data blank_a4.jrxml2.16 KB
prusyn's picture
4024
Joined: Feb 22 2018 - 3:49am
Last seen: 2 years 11 months ago

Only number have "decimal" digits so you'll have to convert your String to some number.

 

hozawa's picture
190913
Joined: Apr 24 2010 - 4:31pm
Last seen: 4 years 3 months ago
Feedback
randomness