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: 

How to determine the second decimal of currency is equal to 0.

Former Member
0 Kudos

Hi guys,

My problem is how to determine the second decimal of currency is equal to 0.

i.e: 130.23 the second decimal is 3.

Thx in advance.

Points will be rewarded.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Execute the code and see if this logic is working for u tan.

data : val type p decimals 2 value '130.23',
       rem(4) type c,
       val1(2) type n.

       rem = frac( val ).
       val1 = rem.
       write:/ '2nd place of val is ' , val1+1(1).

regards,

vijay

10 REPLIES 10

Former Member
0 Kudos

Hi,

use split at . and chek the offset value for the positrion.

Thanks

Shiva

Former Member
0 Kudos

data: g_amt(10) type c,

g_dec(2) type c.

move itab-amt to g_amt.

split g_amt at '.' into g_amt g_dec.

if g_dec+0(2) = 0.

endif.

Former Member
0 Kudos

Hi Vincent,

You van use the MOD operator to determine this.

Regards,

John.

anversha_s
Active Contributor
0 Kudos

hi,

Move the currenct to a character field.

data: l_amnt(100) type c.
numer(10), deci(10)

l_amnt = '12.56'.

Then take the offset.

SPLIT AT l_amnt '.' INTO numer  deci.

WRITE / deci+0(2).

Rgds

Anver

andreas_mann3
Active Contributor
0 Kudos

Hi,

use

y = 130.23

X = frac( y ).

former_member181962
Active Contributor
0 Kudos

One more method:

v_int = v_value * 100.

v_mod = v_int mod 10.

if v_mod = 0.

Write:/ 'The second decimal is 0'.

endif.

Regards,

Ravi

Former Member
0 Kudos

hi,

its simple.

use split command. split the number at the decimal place.

take the second part and use it .

split <value> at . into a b.

write:/ b(1).

Clemenss
Active Contributor
0 Kudos

Hi Vincent,

if you want to check the internal currency value, you can not know from the field contents what is the second decimal. Because ABAP currency fields (CURR) are connected to currency key CUKY. For USD or EUR you have two decimals, japanese yen have no decimals where as some arabian pound have three decimals. The default are 2 decimals; all excetions can be found in table TCURX.

If you WRITE the value it is converted correctly according to the connected currency.

Just multiply the value with 10 to the power of decimals, e.g. USD value * ( 10 ** 2 ). Then do a MOD: second_decimal_of_currency = ( value * ( 10 ** decimals ) mod 10.

If result is zero, then the second decimal of currency is equal to 0.

Regards,

Clemens

Former Member
0 Kudos

Execute the code and see if this logic is working for u tan.

data : val type p decimals 2 value '130.23',
       rem(4) type c,
       val1(2) type n.

       rem = frac( val ).
       val1 = rem.
       write:/ '2nd place of val is ' , val1+1(1).

regards,

vijay

Former Member
0 Kudos

check this with options

130.20 , 130.00 , 130.23.

data : val type p decimals 2 value '130.00',
       rem(4) type c,
       val1(2) type n.

       rem = frac( val ).          "take the frac part
       rem = rem * 100.        "get rid of decimal
       val1 = rem.                 "capture the decimal part
       write:/ val1.

       if val1+1(1) is initial  .         "check 2nd decimal for 0
       write:/ '2nd place is zero'.
       endif.

regards,

vijay.