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: 

Currency amount formatting

Former Member
0 Kudos

hi,

I have the data(amount) taken from currency field it has the amount value like (1,456.78) I need to remove the comma and periods here just get the number (145678) in the char format. How can I do this?

Thanks for your help in advance.

Santhosh

1 ACCEPTED SOLUTION

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Here ya go...



data: x(20) type c value '1,234.78'.



replace ',' with space into x.
replace '.' with space into x.
condense x no-gaps.


check x is initial.

Regards,

Rich Heilman

6 REPLIES 6

Former Member
0 Kudos

Here is a way.

WRITE v_amountfield CURRENCY v_currencykey TO v_charfield NO-GROUPING.

TRANSLATE v_charfield USING '. '.

CONDENSE v_charfield NO-GAPS.

Srinivas

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Here ya go...



data: x(20) type c value '1,234.78'.



replace ',' with space into x.
replace '.' with space into x.
condense x no-gaps.


check x is initial.

Regards,

Rich Heilman

0 Kudos

Thanks Rich. It was really helpful.

Santhosh

0 Kudos

Also, you may want to wrap the REPLACE statements in a WHILE loop. If you number is like 1,513,561.84 the code will only get rid of one of the commas. Do something like this.



data: x(20) type c value '1,511,234.78'.

while x ca ',.'.
  replace ',' with space into x.
  replace '.' with space into x.
endwhile.

condense x no-gaps.

Regards,

Rich Heilman

Former Member
0 Kudos

Hi Santhosh,

The reason why I gave you the combination of WRITE and TRANSLATE is that it takes care of the following

1. WRITE with CURRENCY will take care of the number of decimal places to be used.

2. WRIT with NO GROUPING will take care of removing the separators for thousands etc.

3. TRANSLATE takes care of replacing all your '.'s or ','s with spaces.

Finally CONDENSE NO GAPS gets rid of the spaces.

Just food for thought.

0 Kudos

thanks for the input. It really helped.