Application Development 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: 

Format to 3 decimal places

Former Member
0 Kudos
3,271

Hi all,

I want any given number to be formatted to 3 decimal places.

For example:

1.3 => 1.300

2.35 => 2.350

that's simple, but I want whole numbers to be converted like:

12 => 0.012

56324 => 56.324

How can I achieve this?

Greetings Fred.

1 ACCEPTED SOLUTION

Former Member
0 Kudos
1,386

data : num type p decimals 3.

data : text(13).

<take the variable value in num>

text = num.

if text cp '*.000'."check whether it is a whole no or decimal if whole no then

"only devide

num = num / 1000.

endif.

regards

shiba dutta

10 REPLIES 10

Former Member
0 Kudos
1,386

Use the function <b>Round</b>

<b>write w_value round 3.</b>

U will get the required output.

regards,

sai ramesh

Former Member
0 Kudos
1,386
divide them by 1000

data : v_num type p decimals 3 value '12'.

v_num = v_num / 1000.

Former Member
0 Kudos
1,387

data : num type p decimals 3.

data : text(13).

<take the variable value in num>

text = num.

if text cp '*.000'."check whether it is a whole no or decimal if whole no then

"only devide

num = num / 1000.

endif.

regards

shiba dutta

Former Member
0 Kudos
1,386

HI Fred,

do this way ..

   DATA : V_P(10) TYPE P DECIMALS 3.

V_P = 12 / 1000.

*V_P = V_P * '0.001'.

  WRITE V_P.

regards,

santosh

Message was edited by:

Santosh Kumar Patha

Former Member
0 Kudos
1,386

dear why u try to do this?

any way try with this

DATA : NUM1 TYPE P DECIMALS 3.

DATA : NUM2 TYPE P DECIMALS 3.

NUM1 = 12.

NUM2=56324.

NUM1 = NUM1/1000.

NUM2=NUM1/1000.

0 Kudos
1,386

Hi all,

thanx for the answers. I have not checked all of them, but I think the answer with the check if there is already a decimal can help me.

To all who simply divide the given number do not take into account that I want a number like 1.5 just as 1.500 and not 0.0015.

Greetings Fred.

0 Kudos
1,386

then easy

DATA : NUM1 TYPE I

DATA : NUM2 TYPE P DECIMALS 3.

NUM1 = 12.14.

NUM2 = NUM1.

SO NUM SHOULD BE 12.140.

REWARDS IF HELPFUL.

Former Member
0 Kudos
1,386

Hi Try it in this way

DATA : NUM1 TYPE P DECIMALS 3.
NUM1 = NUM1 / 1000.
WRITE:/ NUM1.

You will get the desired value

                      • Reward point if helpfull---------

Former Member
0 Kudos
1,386

i think for some reason you did not check my answer because i have already check the whole no and decimal.

pls check that if it does not work let me know.

regards

shiba dutta

0 Kudos
1,386

Hi Shiba Dutta,

It was your post with the check for decimal places I mentioned before .

It works great thank you!

Points are rewarded.