[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 223
  • Last Modified:

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.  
0
jramos74
Asked:
jramos74
  • 6
  • 5
  • 3
1 Solution
 
erikTsomikSystem Architect, CF programmer Commented:
it works fine for me
0
 
jramos74Author Commented:
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.
0
 
erikTsomikSystem Architect, CF programmer Commented:
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

0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
_agx_Commented:
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?
0
 
jramos74Author Commented:
Here is what I got  8.66644569466E+012
0
 
jramos74Author Commented:
How do I convert this data to string?  So I can use the phone format above?
0
 
_agx_Commented:
Yes, that's scientific notation.  A simple option is to convert the field to a varchar.
0
 
jramos74Author Commented:
Do I convert it from my query?
0
 
_agx_Commented:
Another option is to try converting the value to a varchar (ie string in your query)

SELECT  CAST(YourColumnName AS varchar(25)) AS WorkNumber
FROM    YourTable
....
0
 
erikTsomikSystem Architect, CF programmer Commented:
0
 
_agx_Commented:
> 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 ?
0
 
jramos74Author Commented:
THANK YOU SO MUCH.  That worked.
0
 
_agx_Commented:
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.
0
 
_agx_Commented:
jramos74,

Glad I could help.
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 6
  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now