hi.
i got a problem.
my Double $F{field} could be more than 2 decimal and to display it is no problem as i can use the pattern to format it.
however, i need to sum the double $F{field} and the result should be exactly same as display in each field.
my question is, how can i sum the $F{field} into a variable with exact 2 decimal???
i am currently using ireport 0.5.3
i got a problem.
my Double $F{field} could be more than 2 decimal and to display it is no problem as i can use the pattern to format it.
however, i need to sum the double $F{field} and the result should be exactly same as display in each field.
my question is, how can i sum the $F{field} into a variable with exact 2 decimal???
i am currently using ireport 0.5.3
1 Answer:
Posted on July 19, 2006 at 7:40am
If you want consider only the first 2 decimals, of a number, you can multiply the number per 100, take the integer part and divide it again:
Suppose TEST is a Double with a primitive value of 1.2345
you have to sum the following value:
new Double( ((int)($P{TEST}.doubleValue() * 100)) / 100.0 )
If effect if you print this value, you'll get 1.2300
(use 4 decimals in the pattern to be sure)
Giulio
Suppose TEST is a Double with a primitive value of 1.2345
you have to sum the following value:
new Double( ((int)($P{TEST}.doubleValue() * 100)) / 100.0 )
If effect if you print this value, you'll get 1.2300
(use 4 decimals in the pattern to be sure)
Giulio