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

simple code help

Former Member
0 Likes
776

Hi,

I have a field value like this

f1 = 12.987

I must show only f1 = 12.9

How dod i do this?

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
757

Hi,

You can try using in the function module ROUND

Example..

DATA: v_p3 TYPE p DECIMALS 3 VALUE '12.567'.

DATA: v_p1 TYPE p DECIMALS 1.

CALL FUNCTION 'ROUND'

EXPORTING

decimals = 1

input = v_p3

IMPORTING

output = v_p1

EXCEPTIONS

input_invalid = 1

overflow = 2

type_invalid = 3

OTHERS = 4.

WRITE: / v_p1.

THanks,

Naren

10 REPLIES 10
Read only

Former Member
0 Likes
757

HI,

data f2 type p decimal 1.

f2 = f1.

write: f2.

Regards

SAB

Read only

Former Member
0 Likes
757

declare f1 as type p decimals 1. or else declare f2 and type p decimals 1 and move f1 to f2 and display f2.

Award points if it helps you.

Message was edited by:

Vinni

Read only

0 Likes
757

I can't change the definition..I have to write some other code

Read only

0 Likes
757

In that case you can create a local variable as below and pass its value to the original variable afterwards:

data f2 type p decimal 1.

f2 = f1.

f1 = f2.

Here F1 will have value as 12.900

Is that okay?

Read only

0 Likes
757

You don't have to change the definition of f1. you can declare another variable f2 and can use that.

Read only

0 Likes
757

hi,

u can also try this..

data f1 type string.

data: one type string.

data: two type string.

data: three type string.

f1 = '12.953'.

split f1 at '.' into one two.

three = two+0(1).

concatenate one '.' three into one.

write: one.

Regards

SAB

Read only

0 Likes
757

I must even round up the decimal

Read only

0 Likes
757

You don't have to when you declare your other variable v2 as type p decimals 1. you will achieve what you wanted.

Read only

Former Member
0 Likes
757

Hi,

If you want to round use the CEIL function..

<b>Example</b>

DATA: v_p3 TYPE p DECIMALS 3 VALUE '12.987'.

DATA: v_p1 TYPE p DECIMALS 1.

v_p1 = ceil( v_p3 ).

WRITE: / v_p1.

Thanks,

Naren

Read only

Former Member
0 Likes
758

Hi,

You can try using in the function module ROUND

Example..

DATA: v_p3 TYPE p DECIMALS 3 VALUE '12.567'.

DATA: v_p1 TYPE p DECIMALS 1.

CALL FUNCTION 'ROUND'

EXPORTING

decimals = 1

input = v_p3

IMPORTING

output = v_p1

EXCEPTIONS

input_invalid = 1

overflow = 2

type_invalid = 3

OTHERS = 4.

WRITE: / v_p1.

THanks,

Naren