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

Rounding off

Former Member
0 Likes
873

Hi experts,

Is there any way (code or FM) to round off a decimals value?

Thanks and Regards,

Ravi

Hi experts,

Is there any way (code or FM) to round off a decimals value?

Thanks and Regards,

Ravi

5 REPLIES 5
Read only

Former Member
0 Likes
832

Hai,

You can use the numerical Function ROUND to round off the decimal places.

<b>round_or_trunc_spec</b>

Syntax Rules for Column Descriptions

Syntax

<round_or_trunc_spec> ::= ROUND <valFRACTION> | TRUNC <valFRACTION>

valFRACTION

Number of decimal places

The value must be between 0 and 18. This function doe not have any effect if the number does not have any decimal places.

Use

Use this syntax rule to specify the number of decimal places in a number.

ROUND <valFRACTION>

The value is rounded off at the (<valFRACTION>1) th decimal place. If this number is >= 5, the value is rounded up. If it is < 5, the value is rounded down. The result is a number in which the (<valFRACTION>1)th and all subsequent decimal places are equal to 0. The other digits in the number may have been changed if the value was rounded up.

DATALOAD TABLE distance

...

cm 7 SCALE 2

cm 7 SCALE -3 ROUND 1

...

INFILE 'meter.data'

TRUNC <valFRACTION>

The (<valFRACTION>+1)th and all subsequent decimal places of the value are set to 0. The first <valFRACTION> decimal places remain unchanged.

DATAEXTRACT * FROM distance

cm 10-14 INTEGER SCALE 2

m 14-17 INTEGER

km 18-21 INTEGER SCALE -3 TRUNC 2

OUTFILE 'dimensions.bin' FORMATTED

Regards,

Ajith V

Read only

former_member673464
Active Contributor
0 Likes
832

hi ...

You can use Round option for rounding the decimal values.

for eg:

DATA pack TYPE p VALUE '123.456'

DECIMALS 3.

WRITE pack DECIMALS 2. "123,46

WRITE: / pack ROUND -2, " 12.345,600

/ pack ROUND -1, " 1.234,560

/ pack ROUND 1, " 12,346

/ pack ROUND 2. " 1,235

regards,

veeresh

Read only

Former Member
0 Likes
832

U declare that field as packed decimal.

eg. data: qty type p.

regards

anju

Read only

0 Likes
832

check FM 'J_1I6_ROUND_TO_NEAREST_AMT'

Read only

former_member196280
Active Contributor
0 Likes
832

Try to move the value to data type "P" , automatic rounding take place.

EX:

DATA :num TYPE P decimals 2.

MOVE '123.456' TO NUM. <b>"output 123.46</b>

WRITE num.

MOVE '123.454' TO NUM. <b> "output 123.45</b>

WRITE num.

Regards,

Sairam