Link to home
Start Free TrialLog in
Avatar of jramos74
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.  
Avatar of erikTsomik
erikTsomik
Flag of United States of America image

it works fine for me
Avatar of jramos74
jramos74

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>

Open in new window

Avatar of _agx_
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?
Here is what I got  8.66644569466E+012
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.
Do I convert it from my query?
ASKER CERTIFIED SOLUTION
Avatar of _agx_
_agx_
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
> 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 ?
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.
jramos74,

Glad I could help.