cancel
Showing results for 
Search instead for 
Did you mean: 

Decimal format to 2 decimal places ????

Former Member
0 Kudos

Hello Everyone,

I have created a web dynpro application which to display a report depending on the data given by the BAPI. But there is some issue with the numeric data returned by the BAPI.

For ex - if the BAPI returns 5.00 the value is displayed in the report as 5.

I want uniform decimal values till 2 decimal places. For example 5 shd come as 5.00, 2.1 shd come as 2.10 etc.

I searched SDN abt this, and found many threads relating to this.

I tried using decimal format, creating a simple dictinary type, but using all this what happens is the value basically changes to a string format, this implies that the value is displayed in the table as "left-aligned".

Where- as we need the decimal numeric values to be right-aligned.

Any thoughts how to achieve this.

Please correct me if I have missed out on anything.

Thanks,

Samta

Accepted Solutions (0)

Answers (5)

Answers (5)

Former Member
0 Kudos

Hi Samta,

This one worked for me. Pls try the following

1. Create a dictionary simple type of type double.

2. In Representation tab, give #.00 for Format.

3. Create context variable and assign its type to the above simple type.

4. Bind this variable to the UI element u want

5. Get the value as double from backend (let it be 123.4). Assign that value to the

context variable created.

The value displayed will be 123.40 which is the one u want.

The context variable now created accepts only double values(not string), so the value dispalyed will be right aligned

Hope this will be helpful

Regards

Fahad Hamsa

Former Member
0 Kudos

Hi,

Create a simpletype with decimal as the built-in type. Assign it to the attribute. At runtime, you can get the value of this Attribute as a BigDecimal.

BigDecimal bg = ele.get<attribute>;

Then you can set the scale as:

bg.setScale(2);

Hope that helps.

Rajit

Ofcourse set it back into the element.

Message was edited by:

Rajit Srinivas

Former Member
0 Kudos

Hey Rajit,

Created a simpletype with decimal as the built-in type.

Assigned it to the attribute.

Have written the following piece of code -

BigDecimal bg = outelem.getEst();

bg.setScale(2);

velem.setEst(bg);

However, it still truncates the decimal places.

Any idea.

Thanks,

Samta

Former Member
0 Kudos

Hi,

Along with this solution, may be you should check the number of decimal places you mentioned while creating the simple type. Shudnt it be 2?

Thats how it works for me. Other than this cant think of anything else!!

Rajit

Former Member
0 Kudos

Hey Rajit,

Yep have done that too.

Still its not working for me,

Any idea. Have i missed out on something else.

Please help.

Thanks,

Samta

Former Member
0 Kudos

Hi,

From wat i understood.. u have a attribute coming from BAPI.. which you want to display with two decimal places,,

In this case.. assuming it is coming with 2 decimal places from the backend.. create a value node.. inside the node which contains the output data. set its carinality to 1..1 .. create a value attribute of type big decimal in it.. or probably string.. if there is an issue in displaying BigDecimal directly..

map this new attribute to the necessary column in the table..

BigDecimal value = new BigDecimal("the actual value in string or long").setScale(2);

assign this to the value attribute created..

(If alignment is the problem.. set the column 's textview property halign to right.. and layout as block or paragraph.. )

Regards

Bharathwaj

Message was edited by:

Bharathwaj R

Former Member
0 Kudos

Hi,

the field what u getting the decimal value varaiable needs to chage as Char then that might helps you.

We had face same prob in R/3 side we simply chage the data type as Char.

Thanks,

Lohi.

Former Member
0 Kudos

Hello Lohitha,

Changing the field to char also changes the display of the field in the table from right-aligned to left-aligned.

We want all numeric fields to be right-aligned.

Any idea on this. Please help.

Thanks,

Samta

Former Member
0 Kudos

hi,

create a simple type of type decimal. Go to the representation tab . In that under the external representation give <b>#0.00##</b> in the format input field.

This will solve your problem.

Regards,

Gopi

Former Member
0 Kudos

Hello Gopi,

I have tried this already, however this changes the display of the field in the table from right-aligned to left- aligned.

And, we want the numeric field to be right aligned.

Any idea

Please help.

Thanks,

Samta

Former Member
0 Kudos

Did you use a numeric type as "built-in type"?

Armin

Former Member
0 Kudos

hi samta,

use the data type as <b>double</b> instead of decimal. you will definetly get it.

Regards,

Gopi

Former Member
0 Kudos

Hey Armin,

It is the type returned by the bapi, currency type 12 char and 2 dec places.

Thanks,

Samta

Former Member
0 Kudos

Hello Gopi,

I changed it to double, still the .00 gets truncated and the number gets displayed as a whole integer.

Thanks,

Samta

Former Member
0 Kudos

Samta,

The simplest thing is just to set align on Column object of your report's Table.

Valery Silaev

SaM Solutions

http://www.sam-solutions.net

Former Member
0 Kudos

Hello Valery,

I set the halign as right and even forcedright, but this doesnt seem to work.

Thanks,

Samta