cancel
Showing results for 
Search instead for 
Did you mean: 

Conversion of Bigdecimal

Former Member
0 Kudos

Hi,

I have a input field Amount of type Bigdecimal.

i have to sum the column data Amount; after that the total is passed to Amount(Bigdecimal) input field.

The code for calculation is as follows:

public void onActionTotalOfAmount(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )

{

//@@begin onActionTotalOfAmount(ServerEvent)

int NodeSize = wdContext.nodeCtx_Claim_Create().size();

float Amount = 0;

for(int i=0;i<NodeSize;i++)

{

Amount = Amount + wdContext.nodeCtx_Claim_Create().getCtx_Claim_CreateElementAt(i).getCtx_Amount();

wdContext.currentContextElement().setCtx_Total(Amount);

}

But when i am passing the Amount to input field(Bigdecimal) the error is type missmatch.

Please tell me that how to convert the Amount(float) to Amount (big decimal).

Regards

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

use -

Amount = Amount.add(wdContext.nodeCtx_Claim_Create().getCtx_Claim_CreateElementAt(i).getCtx_Amount());

instead of

Amount = Amount + wdContext.nodeCtx_Claim_Create().getCtx_Claim_CreateElementAt(i).getCtx_Amount();

Aviad

Edit:

Do not use float for amount. use -

BigDecimal Amount = new BigDecimal(0);

Edited by: Aviad Levy on Jul 21, 2008 3:24 PM

Answers (1)

Answers (1)

PradeepBondla
Active Contributor
0 Kudos

Hi,

in general to convert float to big decimal

* To convert Float to BigDecimal.
      * @param f the Float to be converted
      * @return converted BigDecimal
      */
     public BigDecimal toBigDecimal(Float f) {
          return (f == null) ? null : new BigDecimal(f.toString());
     }

that is.....

BigDecimal big = new BigDecimal(floatX.toString());

apply it as you want.

PradeeP