2007 Jul 23 8:19 AM
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
2007 Jul 23 8:23 AM
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
2007 Jul 23 8:27 AM
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
2007 Jul 23 8:29 AM
U declare that field as packed decimal.
eg. data: qty type p.
regards
anju
2007 Jul 23 8:34 AM
2007 Jul 23 8:32 AM
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
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |