cancel
Showing results for 
Search instead for 
Did you mean: 

Setting a bigdecimal value in a integer column.

Former Member
0 Kudos

Hi,

I want to set the average of a particular column values in the last row of the table.I have written the code for calculating the average, and also to add a row in the table.But the problem is that im not able to set the average value in the column as it is of type int and the average is a big decimal.I dont want to convert it to int value.Can anyone suggest me how to proceed with this?

Regards,

Padmalatha.K

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

You could add an additional (calculated) attribute "BigDecimalValue" of DDIC type "decimal" under the data source node of the table and bind the column cell editor to this attribute instead to the "integer" attribute "IntegerValue".

The getter would be something like


BigDecimal getBigDecimalValue(...element)
{
  BigDecimal.valueOf( element.getIntegerValue() );
}

This will however change all cells in this table column to BigDecimal.

If you only want this in the last row, you can use table cell editor variants (NW04s and later).

Armin

Former Member
0 Kudos

I am not able to add a context attribute as im getting -

Adding Attributes is currently not supported if the node or the model has a dictionary structure binding.

Please suggest.

Regards,

Padmalatha.K

Former Member
0 Kudos

Hi Padma,

You can add the attribute in node of the view where you are displaying the table.

Regards,

Gopal

Former Member
0 Kudos

Hi Armin,

Thanks for your reply. I am not getting you properly. Pls explain. Do you mean that I have to add an attribute to a node which is bound from model? If so, I am not able to add an attribute to this node.

Pls suggest.

Regards,

Padmalatha.K

Former Member
0 Kudos

In that case add a value node "Additional" (cardinality 1:1, selection 1:1) to the data source node and add the calculated attribute inside this value node.

In the getter for the calculated attribute, you then have to access the parent element:


BigDecimal getBigDecimalValue(IAdditionalElement element)
{
  I<DataSourceNode>Element parent = (I<DataSourceNode>Element) element.node().getParentElement();
  return BigDecimal.valueOf( parent.getIntegerValue() );
}

Armin

Former Member
0 Kudos

Hi Armin,

I have created a value node "Additional" and set the cardinality and selection property as you said.For this node, i created a context attribute "att" of type bigdecimal and made the ReadOnly and Calculate Property as true.So i got an auto generated method for this attribute.

I have written the following code in this method:

Iprivate<viewname>.iadditionalNode parent = wdcontext.nodeAdditional();

Iprivate<viewname>.iadditionalElement parentElem = parent.getParetnt();

I am not getting any option like u mentioned.

I<DataSourceNode>Element parent = (I<DataSourceNode>Element) element.node().getParentElement();

return BigDecimal.valueOf( parent.getIntegerValue() );

But my code also giving error.

I want to set the column value as bigdecimal value.Please tell me how to proceed further.

Regards,

Padmalatha.K

Former Member
0 Kudos

I forgot to mention: set singleton=false for this node.

Armin

Answers (4)

Answers (4)

nikhil_bose
Active Contributor
0 Kudos

you can use data type from dictionary objects for the corresponding field(which is BigDecimal) instead of calculated value

nikhiL

Former Member
0 Kudos

Hi

I cannot change the type of the attribute as it is mapped from the model.

Is there any other way?

Regards,

Padmalatha.K

Former Member
0 Kudos

Here is one more solution.

Suppose your node is Abc under which you have integer attribute, say att.

Under this node create a calculated attribute of type decimal. Suppose attribute name is calcAtt. Set data type of thhis attribute as decimal. Set readOnly attribute to true and calculated property to true. You will get auto generated method as following:

//@@begin javadoc:getCalcAtt(IPrivateView.IContextElement)
  /**
   *  Declared getter method for attribute calcAtt of node Context
   *  @param element the element requested for the value
   *  @return the calculated value for attribute calcAtt
   */
  //@@end
  public java.math.BigDecimal getCalcAtt(IPrivateView.IContextElement element)
  {
    //@@begin getCalcAtt(IPrivateView.IContextElement)
    return null;
    //@@end
  }

Now instead of return null, write following code:

return new BigDecimal(wdContext.currentAbcElement().getAtt1());

P.s Change name of node and attribute name according to you node and attribute name.

Now do all manipulation that you were initially doing on Integer attribute to this calculated attribute.

Regards,

Gopal

Former Member
0 Kudos

Hi Sunitha,

But when i convert the bigdecimal to an integer, it will truncate the decimal part of the value.

int i = bd.intValue(); // bd is big decimal Object

Integer i = new Integer(bd.intValue());

For example, if the bigdecimal value is 6.12 and i convert it to integer, it will have 6 as the value.I want the exact value(6.12) and i want to set it to a integer column without losing the precision.

Can you please guide me how to do it?

Regards,

Padmalatha.K

Former Member
0 Kudos

Change the data type of attribute from integer to decimal.

Regards,

Gopal

Former Member
0 Kudos

Hi Latha ,

Interger variable will not hold a decimal values.

If Avg is 6.12 then integer var will hold only 6.

you can use a float varaible instead of Integer in your scenario.

Thanks,

Sunitha

Former Member
0 Kudos

Hi ,

int i = bd.intValue(); // bd is big decimal Object

Integer i = new Integer(bd.intValue());

Regards,

Sunitha Hari