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

Remove Decimals from Number

Former Member
0 Likes
1,131

Hi Gurus,

Before posting this thread, i serached SDN and i could not find proper answer for my requirement.

My Question is , i have a text filed which will contain a numeric value. say .5 . the desired output should be 0050.

means , it should remove the decimals from text and result output shuold contain 4 characters. (It should consider 2 numbers before decimal and 2 numbers after decimal)

any suggestions pls..

Thanks

Meher

Hi Gurus,

Before posting this thread, i serached SDN and i could not find proper answer for my requirement.

My Question is , i have a text filed which will contain a numeric value. say .5 . the desired output should be 0050.

means , it should remove the decimals from text and result output shuold contain 4 characters. (It should consider 2 numbers before decimal and 2 numbers after decimal)

any suggestions pls..

Thanks

Meher

7 REPLIES 7
Read only

Former Member
0 Likes
1,036

Hi ,

first of all use translate statement

use this statement for replacing . by space ,

translate p_field by '. space'.

then . will be removed then use condence p_field with no gaps.

PLease let me know if you still have any issues on this.

Thanks and regards,

Rajeshwar.

Read only

0 Likes
1,036

Thanks Rajeswar,

I did it, but still this logic is not working for some cases like...one which i mentioned in my question.

Let me explain bit clear..

if the text contains .5 (point 5), result should be 0050. means it should take 2 numbers before decimal place and 2 numbers after decimal.

the suggested logic will not work in this case.

Please clarify me..

Thanks

Meher

Read only

Former Member
0 Likes
1,036

See this code:

v_number = '.5'.

v_whole = trunc( v_number ).

v_deci = frac( v_number ).

concatenate v_whole v_deci into v_newnum.

you may need to put the whole and deci into a character variable; just adjust accordingly...

v_whole and v_deci are type N of length 2

hope this helps

Edited by: Chris C. on Jul 28, 2009 8:39 AM

Read only

venkat_o
Active Contributor
0 Likes
1,036

Hi Rakesh, Try this way. Its very simple.

data: v_char(2) type c value '.5'.
data: v_num(4)  type n.

v_num = v_char * 100.
write v_num.
Thanks Venkat.O

Read only

Former Member
0 Likes
1,036

Thanks Venkat.

Problem solved. Thank you very much all for your valuable suggestions..

Read only

Former Member
0 Likes
1,036

Can you try in this way:

DATA: INPUT(4) type c value '1.5',

var1(2) type N,

output type string,

fst type string,

sec type string.

split input at '.' into fst sec.

var1 = fst.

fst = var1.

var1 = sec.

sec = var1.

concatenate fst sec into output.

write output.

Read only

Former Member
0 Likes
1,036

Hi ,

then in this case first find the string length using STRLEN statement and then use if condition.

P_val = STRLRN(p_field) .

if p_val = 2.

translate p_val ' . '.

condence no gaps.

then use

concatenate '00' p_val 'oo' into p_val.

elseif = 3.

endif.

Please let me know if you still have any issues on this.

Thanks and regards,

Rajeshwar.