RE: string to number
Drop the quotes. Cold Fusion uses type less variables and will convert strings to numbers easily. You need to build in checks to ensure that the passed form variables are indeed numeric before you do any math on them. Russel Russel Madere, Jr. Senior Web Developer ICQ: 5446158 http://www.TurboSquid.com Some days you eat the bear; some days the bear eats you. > -Original Message- > From: Steve Doran [mailto:[EMAIL PROTECTED]] > Sent: Thursday, January 18, 2001 07:36 > To: CF-Talk > Subject: string to number > > > I am trying to get a variable to work that would tell me how many rooms a > person would need if they has X amount of people in their party. > > Here is the Code I am working with: > > > > > > > > > > > > > > > > > > > > > > > > The problem I am having is when you output grp it gives you the total of > form.adult + form.children. But when you use grp to set the variable > SmRmRq it goes to a string "number + number" and will not accurately > convert the variable. > > Is there a way to change the grp to a number? In Javascript It would be > something like Var = (parseInt(form.adult) + parseInt(form.children)) > > Thanks in advance for any assistance, > > Steve Doran :) > > > ~~ Structure your ColdFusion code with Fusebox. Get the official book at http://www.fusionauthority.com/bkinfo.cfm Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/ Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists
RE: string to number
My idea is this (you wont really find it in a CS tome.. just various peoples opinons on style) If it makes the code more readable then comapct it. If nothing is gained by compacting the code... dont do it unless you comment the code well. The main thing to watch out for is to make sure your code stays readable so that when you come back to it months later you can still understand what you did (and anyone else who might have the mischance to maintain code they did not write ;) Jeremy Allen elliptIQ Inc. >-Original Message- >From: Cornillon, Matthieu [mailto:[EMAIL PROTECTED]] >Sent: Thursday, January 18, 2001 10:12 AM >To: CF-Talk >Subject: RE: string to number > > >Steve, > >As long as you keep your ranges as you have them in your If statements, the >following formula should yield the correct result. I know this doesn't >address the question that you asked, but others have responded to that, and >I just couldn't help fiddling. Hope you don't mind. > > > > > > > >Of course, this is harder to modify in the future, should one range change. >I'm also not sure whether it runs slower or faster. I am still not sure >whether my obsession with physically compact code runs counter to good >programming sense. I guess I should flip through a CS book! > >Matthieu > >> -Original Message- >> From: Steve Doran [mailto:[EMAIL PROTECTED]] >> Sent: Thursday, January 18, 2001 8:36 AM >> To: CF-Talk >> Subject: string to number >> >> >> I am trying to get a variable to work that would tell me how >> many rooms a >> person would need if they has X amount of people in their party. >> >> Here is the Code I am working with: >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> The problem I am having is when you output grp it gives you >> the total of >> form.adult + form.children. But when you use grp to set the variable >> SmRmRq it goes to a string "number + number" and will not accurately >> convert the variable. >> >> Is there a way to change the grp to a number? In Javascript >> It would be >> something like Var = (parseInt(form.adult) + parseInt(form.children)) >> >> Thanks in advance for any assistance, >> >> Steve Doran :) >> >> >> > ~~ Structure your ColdFusion code with Fusebox. Get the official book at http://www.fusionauthority.com/bkinfo.cfm Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/ Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists
RE: string to number
To somewhat answer part of this, in the past I've come to the conclusion that IIF is slower than CFIF; I don't remember if that's based on my own tests or someone else's reports. I still use IIF when it makes something generally more readable, but not too often... -Original Message- From: Cornillon, Matthieu [mailto:[EMAIL PROTECTED]] Sent: Thursday, January 18, 2001 10:12 AM To: CF-Talk Subject: RE: string to number Steve, As long as you keep your ranges as you have them in your If statements, the following formula should yield the correct result. I know this doesn't address the question that you asked, but others have responded to that, and I just couldn't help fiddling. Hope you don't mind. Of course, this is harder to modify in the future, should one range change. I'm also not sure whether it runs slower or faster. I am still not sure whether my obsession with physically compact code runs counter to good programming sense. I guess I should flip through a CS book! ~~ Structure your ColdFusion code with Fusebox. Get the official book at http://www.fusionauthority.com/bkinfo.cfm Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/ Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists
RE: string to number
Take the quotes out of "form.adult + form.children" You can also use VAL val(form.adult) + val(form.children) tim p. -Original Message- From: Steve Doran [mailto:[EMAIL PROTECTED]] Sent: Thursday, January 18, 2001 8:36 AM To: CF-Talk Subject: string to number I am trying to get a variable to work that would tell me how many rooms a person would need if they has X amount of people in their party. Here is the Code I am working with: The problem I am having is when you output grp it gives you the total of form.adult + form.children. But when you use grp to set the variable SmRmRq it goes to a string "number + number" and will not accurately convert the variable. Is there a way to change the grp to a number? In Javascript It would be something like Var = (parseInt(form.adult) + parseInt(form.children)) Thanks in advance for any assistance, Steve Doran :) ~~ Structure your ColdFusion code with Fusebox. Get the official book at http://www.fusionauthority.com/bkinfo.cfm Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/ Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists
RE: string to number
Steve, As long as you keep your ranges as you have them in your If statements, the following formula should yield the correct result. I know this doesn't address the question that you asked, but others have responded to that, and I just couldn't help fiddling. Hope you don't mind. Of course, this is harder to modify in the future, should one range change. I'm also not sure whether it runs slower or faster. I am still not sure whether my obsession with physically compact code runs counter to good programming sense. I guess I should flip through a CS book! Matthieu > -Original Message- > From: Steve Doran [mailto:[EMAIL PROTECTED]] > Sent: Thursday, January 18, 2001 8:36 AM > To: CF-Talk > Subject: string to number > > > I am trying to get a variable to work that would tell me how > many rooms a > person would need if they has X amount of people in their party. > > Here is the Code I am working with: > > > > > > > > > > > > > > > > > > > > > > > > The problem I am having is when you output grp it gives you > the total of > form.adult + form.children. But when you use grp to set the variable > SmRmRq it goes to a string "number + number" and will not accurately > convert the variable. > > Is there a way to change the grp to a number? In Javascript > It would be > something like Var = (parseInt(form.adult) + parseInt(form.children)) > > Thanks in advance for any assistance, > > Steve Doran :) > > > ~~ Structure your ColdFusion code with Fusebox. Get the official book at http://www.fusionauthority.com/bkinfo.cfm Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/ Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists
RE: string to number
I think what you want . (no quotes) ~Simon > Simon Horwith > Allaire Certified ColdFusion Instructor > Certified ColdFusion Developer > Fig Leaf Software > 1400 16th St NW, # 220 > Washington DC 20036 > 202.797.6570 (direct line) > www.figleaf.com > -Original Message- From: Steve Doran [mailto:[EMAIL PROTECTED]] Sent: Thursday, January 18, 2001 8:36 AM To: CF-Talk Subject: string to number I am trying to get a variable to work that would tell me how many rooms a person would need if they has X amount of people in their party. Here is the Code I am working with: The problem I am having is when you output grp it gives you the total of form.adult + form.children. But when you use grp to set the variable SmRmRq it goes to a string "number + number" and will not accurately convert the variable. Is there a way to change the grp to a number? In Javascript It would be something like Var = (parseInt(form.adult) + parseInt(form.children)) Thanks in advance for any assistance, Steve Doran :) ~~ Structure your ColdFusion code with Fusebox. Get the official book at http://www.fusionauthority.com/bkinfo.cfm Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/ Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists
RE: string to number
You want this: When setting quotes around it, CF assumes it's a string. rgds * Holger Lockertsen, Solutions Developer * Pixelduck AS - Nedre Slottsgate 5, N-0157 OSLO, Noreg/Norway * 23 31 03 04 / 91 83 20 51 * [EMAIL PROTECTED] * http://www.pixelduck.com/ > -Original Message- > From: Steve Doran [mailto:[EMAIL PROTECTED]] > Sent: Thursday, January 18, 2001 2:36 PM > To: CF-Talk > Subject: string to number > > > I am trying to get a variable to work that would tell me how > many rooms a > person would need if they has X amount of people in their party. > > Here is the Code I am working with: > > > > > > > > > > > > > > > > > > > > > > > > The problem I am having is when you output grp it gives you > the total of > form.adult + form.children. But when you use grp to set the variable > SmRmRq it goes to a string "number + number" and will not accurately > convert the variable. > > Is there a way to change the grp to a number? In Javascript > It would be > something like Var = (parseInt(form.adult) + parseInt(form.children)) > > Thanks in advance for any assistance, > > Steve Doran :) > > > ~~ Structure your ColdFusion code with Fusebox. Get the official book at http://www.fusionauthority.com/bkinfo.cfm Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/ Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists
string to number
I am trying to get a variable to work that would tell me how many rooms a person would need if they has X amount of people in their party. Here is the Code I am working with: The problem I am having is when you output grp it gives you the total of form.adult + form.children. But when you use grp to set the variable SmRmRq it goes to a string "number + number" and will not accurately convert the variable. Is there a way to change the grp to a number? In Javascript It would be something like Var = (parseInt(form.adult) + parseInt(form.children)) Thanks in advance for any assistance, Steve Doran :) ~~ Structure your ColdFusion code with Fusebox. Get the official book at http://www.fusionauthority.com/bkinfo.cfm Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/ Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists