Good day all,
well i have been searching the web and i cannot find an answer to my question. First off i dont know if i should post this here or in the Javascript section because i am a coldfusion user and didnt know if javascript does this. Second my problem is i want to add a "." after the 3rd character or letter. Ex.

var str = "0222232"
This is where the function would come in to add a . after the 3rd number. So the output would be 022.2232

Is this possible? I normally show code, but i wouldnt even know where to start. Thanks for the help.

6 Years
Discussion Span
Last Post by levine

i dont know about coldfusion but you should be able to do something like this
substring(0,3) + "." + substring(4,stringLength)
or if you can use it like a numeric value then just multiply by 1000


Thanks divin757,
Your code helped get me started, but then i noticed that it didnt output the whole thing to include the period. So i just changed the value of 4 to 3 and added str to the substrings and length.

var str = "0222232";
document.write(str.substring(0,3) + "." + str.substring(3, str.length))

Again thanks alot.


I guess i should post what i use now, for others to view.

<cffunction name="convert" access="public" returntype="string">
    <cfargument name="latitude" required="yes" type="any">
    <cfargument name="longitude" required="yes" type="any">
    <cfset var lat = "">
    <cfset var long = "">
    <cfset lat = #replace(ARGUMENTS.latitude,".","")#>
    <cfset long = #replace(ARGUMENTS.longitude,".","")#>
    <cfset lat.substring(2,4)&"."&lat.substring(4,len(lat))>
    <cfset long.substring(1,3)&"."&long.substring(3,len(long))>
    <cfset coord = lat&","& long>
    <cfreturn coord>

I am not aware with coldfusion although i am in learning process and your tip is helpful for me.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.