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

Currency amount formatting

Former Member
0 Likes
1,600

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
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,264

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

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
Read only

Former Member
0 Likes
1,264

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

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,265

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

Read only

0 Likes
1,264

Thanks Rich. It was really helpful.

Santhosh

Read only

0 Likes
1,264

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

Read only

Former Member
0 Likes
1,264

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.

Read only

0 Likes
1,264

thanks for the input. It really helped.