jramos74
asked on
Telephone Format Coldfusion
Hi, All. I think this is a coldfusion version problem.
I have the following code:
<input value="(#left(work_phone, 3)#) #right(left(work_phone, 6),3)# - #right(left(work_phone, 10),4)# <cfif len(work_phone) gt 10> ext. #right(left(work_phone, 14),4)#</cfif>" size="40" disabled="disabled" name="usnumber" type="text" />
This convert the data work_phone = 80012345678912 to (800) 123-4567 ext. 8912
The code above works just fine in Coldfusion version 7 but when the same code is run on version 6, I get the following output, (8.6) 123-4567 ext. 891E
Please help.
I have the following code:
<input value="(#left(work_phone, 3)#) #right(left(work_phone, 6),3)# - #right(left(work_phone, 10),4)# <cfif len(work_phone) gt 10> ext. #right(left(work_phone, 14),4)#</cfif>" size="40" disabled="disabled" name="usnumber" type="text" />
This convert the data work_phone = 80012345678912 to (800) 123-4567 ext. 8912
The code above works just fine in Coldfusion version 7 but when the same code is run on version 6, I get the following output, (8.6) 123-4567 ext. 891E
Please help.
it works fine for me
ASKER
I don't know what I am doing wrong. The data type is set as number in the table. It works fine on one server but it is calculating it on the different server.
here what i did. And it works on both versions
<cfoutput><cfset work_phone=000000000000000000000000000000>
<input value="(#left(work_phone, 3)#) #right(left(work_phone, 6),3)# - #right(left(work_phone, 10),4)# <cfif len(work_phone) gt 10> ext. #right(left(work_phone, 14),4)#</cfif>" size="40" disabled="disabled" name="usnumber" type="text" /></cfoutput>
Are you storing it as some type of floating point number? That could cause a problem if the value is returned in scientific notation. <Cfdump> the #work_phone# value that is giving you trouble. What is the value?
ASKER
Here is what I got 8.66644569466E+012
ASKER
How do I convert this data to string? So I can use the phone format above?
Yes, that's scientific notation. A simple option is to convert the field to a varchar.
ASKER
Do I convert it from my query?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Or you can use Java as well
read this
http://livedocs.adobe.com/coldfusion/7/htmldocs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=ColdFusion_Documentation&file=00001568.htm
read this
http://livedocs.adobe.com/coldfusion/7/htmldocs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=ColdFusion_Documentation&file=00001568.htm
> Do I convert it from my query?
Sorry our timing is off. You could either convert it in your query -OR- change the data type of your table column. The first option is simpler, so try it first. The syntax may vary depending on your db. What database (and version) are you using ?
Sorry our timing is off. You could either convert it in your query -OR- change the data type of your table column. The first option is simpler, so try it first. The syntax may vary depending on your db. What database (and version) are you using ?
ASKER
THANK YOU SO MUCH. That worked.
erikTsomik,
JavaCast is more for converting values passed into java classes. You could use a separate java class to format the 8.66644569466E+012 value, but that is kind of overkill here. I would try the simpler option (convert it in a query) first and use java only if that failed.
JavaCast is more for converting values passed into java classes. You could use a separate java class to format the 8.66644569466E+012 value, but that is kind of overkill here. I would try the simpler option (convert it in a query) first and use java only if that failed.
jramos74,
Glad I could help.
Glad I could help.