Skip to Content
author's profile photo Former Member
Former Member

Convert string to decimal

I want to convert a string '127,280.01' to decimal is there any function module that i can use?

Thanx in advance

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

8 Answers

  • Best Answer
    Posted on Dec 08, 2005 at 04:12 PM

    Jose, try this.

    
    report zrich_0001
           no standard page heading.
    
    
    
           data: s type string.
           data: p Type p decimals 2.
    
    
           s = '127,280.01'.
    
           translate s using ', '.
    
           condense s no-gaps.
           clear p.
           p = p + s.
    
           write:/ p.
    
    

    Here we are removing the , for the thousands separator, condensing and just adding the value to a P field.

    Regards,

    Rich Heilman

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Dec 08, 2005 at 04:19 PM

    hi joes try this ..FM

    <b>HRCM_STRING_TO_AMOUNT_CONVERT</b>
    STRING                          123,34.567   
    DECIMAL_SEPARATOR               .               
    THOUSANDS_SEPARATOR             ,               
    WAERS         (BALNK)                                 

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 08, 2005 at 04:14 PM

    You can directly assign string variable to packed integer with decimals (Type P) . But the string you have defined contains Comma (,) that is the reason it is not able to convert. use string functions to eliminate the comma from the string and assign to the numeric value.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 08, 2005 at 04:14 PM

    try using FM CONVERT_STRING_TO_INTEGER.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Dec 08, 2005 at 04:17 PM

    Use this

    HRCM_STRING_TO_AMOUNT_CONVERT

    STRING 123,34.567

    DECIMAL_SEPARATOR .

    THOUSANDS_SEPARATOR ,

    WAERS leave it balnk

    you can convert to DEcimal

    regards

    vijay

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Dec 08, 2005 at 04:20 PM

    please reward if you got the solution...

    vijay

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 08, 2005 at 04:22 PM

    u have string as 127,280.01 This is already in decimal notation.

    Just u need to move the char value to integer value.

    data : v1 type p decimals 2.

    move string to v1.

    This solves.

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi

      It's very easy operation, so I don't know if there are some fm.

      You only need to move your string to decimal number by MOVE comand.

      Before moving the string you have to delete the virgola, because the dump occurs:

      So:

      DATA: NUMBER_C(20) VALUE '127,280.01',

      NUMBER TYPE P DECIMALS 2.

      • Here NUMBER_C is 127,280.01

      DO.

      REPLACE ',' WITH SPACE INTO NUMBER_C.

      IF SY-SUBRC <> 0. EXIT. ENDIF.

      CONDENSE NUMBER_C NO-GAP.

      ENDDO.

      • Now NUMBER_C is 127280.01

      MOVE NUMBER_C TO NUMBER.

      Max

      Message was edited by: max bianchi

  • Posted on Dec 08, 2005 at 05:27 PM

    Hi Joes

    Check the Function Module once...

    vijay

    Message was edited by: Vijay Babu Dudla

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.