views:

26

answers:

2

Hi Experts,

How to convert String to Double value in jasper Reports? I am having two fields in .jrxml file like below

    <field name="secRate" class="java.lang.String"/>
    <field name="secPrice" class="java.lang.String"/>

i need to subtract both the field

   $V{Variable} = $F{secRate} - SF{secPrice}

i tried this way but not working

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

any idea? please help me guys..

+1  A: 

If the mktVal field is a String, you can try using Double.valueOf(${mktVal}).

gedim
can you tell me how to convert to BigDecimal(from string to BigDecimal for above question)?
Manu
you can use new BigDecimal(${mktVal})
gedim
I tried this way but not working "new BigDecimal($F{secAcrruedAmt})+ (new BigDecimal($F{secPrice}))".. any idea?
Manu
i got below error: The operator + is undefined for the argument type(s) java.math.BigDecimal, java.math.BigDecimal
Manu
For BigDecimal operations you must use the add(), subtract(), multiply() and divide() methods of the BigDecimal class. In your case:$V{Variable} = new BigDecimal($F{secRate}).subtract(new BigDecimal($F{secPrice}))
gedim
A: 

Try Double.valueOf(${mktVal}).

Dhrumil Shah