Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

decimals values.

Former Member
0 Likes
596

hi experts,

How to get decimla values .

i have used field type p decimals 2.

if 2345.5 then it is coming 2345.5

if the value is 2545 it is coming 2545 but i need an output like this .

2545.00 .what to do ?

regards,

mani

4 REPLIES 4
Read only

Former Member
0 Likes
570

Hi

declare a variable like this

data v_val type NETWR.

move the value to this field

Move number to v_val.

now v_val have 2 decimals

Regards

anji

Read only

Former Member
0 Likes
570

HI,

If you delcare the field like <b>type p decimals 2.</b> then you won;t get the .00 decimals, you need to take the SAP Predefined value to get these values

Regards

Sudheer

Read only

Former Member
0 Likes
570

Hi,

declare tour variable as

data var type p decimals 2.

var1 = '4567.5'.

var = var1.

write var.

var will have 4567.50.

Regards,

Amole

Read only

0 Likes
570

Hi Amole,

I did not believe so I tried:


data: var  type p decimals 2,
      var1 type text40.

var1 = '4567.5'.
var = var1.
write var.

... and what do I get?

456,75

Type P is packed decimal. The number of decimals wll be interpreted when calculations, output or input from screen field is done.

MOVE (= is move) will just move ignoring the decimal point.

You can solve the issue:


  DATA: var  TYPE p DECIMALS 2,
        var1 TYPE text40,
        decimals TYPE i.

  var1 = '4567.5'.
  f = var1.
  DESCRIBE FIELD var DECIMALS decimals.
  WHILE decimals > 0.
    f = f *  10.
    SUBTRACT 1 FROM decimals.
  ENDWHILE.
  var = f.
  WRITE var.

Regards,

Clemens