‎2009 Aug 24 2:46 PM
Hi,
I am relatively new in ABAP and I am searching for a FM or function to convert a given floating point number into a string using a given format (like using the [DecimalFormatter|http://java.sun.com/javase/6/docs/api/java/text/DecimalFormat.html] class in Java).
eg.
Number: 1234.56
Format: #,##0.00
Result 1,234.45
Number: 1234
Format #,##0.00
Result: 1,234.00
Number 0.34
Format: #,###.##
Result: .34
Number: 0.34
Format: #,##0.00
Result. 0.34
Number: 0.56
Format: 0.0
Result: 0.6
Number: 1234.56
Format: abc#,###
Result: abc1,235
and so on
I have already tried the 'using mask' expression in the write command and also the FM 'C14N_NUMERIC_FORMAT' but without my desired results.
Any idea
regards Martin
‎2009 Aug 24 3:32 PM
Hi,
You can use WRITE....TO statement to convert. which converts the contents of the source field into a field with type C
WRITE <f1> TO <f2> <Options>
Eg:
DATA: NUMBER TYPE F VALUE '4.3',
TEXT(10),
FLOAT TYPE F,
PACK TYPE P DECIMALS 1.
WRITE NUMBER TO TEXT EXPONENT 2.
WRITE NUMBER TO FLOAT.
WRITE NUMBER TO PACK.
Regards
Shiva
Edited by: Shiva Kumar Tirumalasetty on Aug 24, 2009 8:03 PM
‎2009 Aug 24 3:54 PM
Thx Shiva,
but this dosn't solve my problem. I 'simply' want to apply a format like described above to the number and thus get the number in the desired format.
eg.
I have a float number 1234.34 which is stored in the float field like 1.23456E+3. I have a format telling me to show only the integer part of this number (like 1234). My idea is to apply a format '###9' to that number and it will give back a string containing '1234'. Likewise with the other format expressed in my original question.
hope this makes my question a bit more understandable.
regards
Martin
‎2009 Aug 24 8:56 PM
I've never seen that. In SAP, we don't bother with formats, we usually have requirements which require only one format. I'm afraid that you have to code it yourself.
‎2009 Aug 24 9:04 PM
Use 'FLTP_CHAR_CONVERSION' in this you can mention the number of decimal place you want to have...
‎2016 Aug 17 1:39 PM
Nowadays, you format numeric data into strings with embedded expressions in string templates and their formatting options:
Embedded expressions - format options
WRITE TO is the old fashioned way ...