Gossamer Forum
Home : Products : DBMan : Customization :

How to convert xxxx to x,xxx

Quote Reply
How to convert xxxx to x,xxx
Does anyone familiar with the command for converting xxxx to x,xxx
i.e. $1000.00 become $1,000.00

thank you
Quote Reply
Re: How to convert xxxx to x,xxx In reply to
Code:
$rec{'number_to_add_commas'} = reverse $rec{'number_to_add_commas'};
$rec{'number_to_add_commas'} =~ s/(\d\d\d)(?=\d)(?!\d*\.)/$1,/g;
$rec{'number_to_add_commas'} = reverse $rec{'number_to_add_commas'};


------------------
Chris
Quote Reply
Re: How to convert xxxx to x,xxx In reply to
Thanks for your quick relply Chris, but it still doesn't show the coma. Frown
Quote Reply
Re: How to convert xxxx to x,xxx In reply to
I tested this code and it works. You need to place the code right after my(%rec) = @_; in the routine you are doing this in. If you still can't get it to work, post the url to the files in txt form.

------------------
Chris
Quote Reply
Re: How to convert xxxx to x,xxx In reply to
It Works!
Thanks a lot Chris.
God Bless You
Quote Reply
Re: How to convert xxxx to x,xxx In reply to
But, wait...
when there is a number with .xx i.e. $1000.50
then it messed up.
-------
=~ s/(\d\d\d)(?=\d)(?!\d*\.)/$1,/g;
-------
Are those 3 Ds represent digits backward?
How can we make the number with .xx (2 digits) be done?

Thanks
Quote Reply
Re: How to convert xxxx to x,xxx In reply to
It worked for me. I tried a number like 1254.55 and I got 1,254.55 and 15544489.25 resulted in 15,544,489.25. Is the $ part of the number? That may be the problem. Try storing the number only and then append the $.

------------------
Chris
Quote Reply
Re: How to convert xxxx to x,xxx In reply to
And append the $ with the escape character:

Code:
\$ $rec{'FieldName'}

Regards,

------------------
Eliot Lee
Anthro TECH,L.L.C
www.anthrotech.com
* Be sure to visit the Resource Center for FAQ's, Modifications and Extra Goodies!!
* Search Forums!
* Say NO to Duplicate Threads. :)
----------------------