at's cool Barney. I didn't know it would be quite that efficient. Any
> performance hits using eval?
>
> -Original Message-
> From: Barney Boisvert [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, July 17, 2007 10:46 AM
> To: CF-Talk
> Subject: Re: Simple JS math?
>
&g
> -Original Message-
> From: Barney Boisvert [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, July 17, 2007 11:46 AM
> To: CF-Talk
> Subject: Re: Simple JS math?
>
> num + eval(frac)
>
> The latter operand will evaluate the string as if it were javascript
> (i.e.
Doing it that way you can't. One is a string, the other's a number. You'd
have to first convert the fraction into it's decimal representation. You
could prolly write a function to do that. Something like this would work:
str = '3/8';
function convertDecimal(str) {
Thanks Barney... That did the trick.
-Original Message-
From: Barney Boisvert [mailto:[EMAIL PROTECTED]
Sent: Tuesday, July 17, 2007 11:46 AM
To: CF-Talk
Subject: Re: Simple JS math?
num + eval(frac)
The latter operand will evaluate the string as if it were javascript (i.e.
do 3 / 8
That's cool Barney. I didn't know it would be quite that efficient. Any
performance hits using eval?
-Original Message-
From: Barney Boisvert [mailto:[EMAIL PROTECTED]
Sent: Tuesday, July 17, 2007 10:46 AM
To: CF-Talk
Subject: Re: Simple JS math?
num + eval(frac)
The latt
It seems to me you have two choices. You can do it as a string (by
converting the 20 to a string and adding a space and the fraction) or as
a number, which will give you a decimal. Which are you trying to
accomplish?
--Ben Doom
Che Vilnonis wrote:
> Looking to add an integer and a fraction.
num + eval(frac)
The latter operand will evaluate the string as if it were javascript
(i.e. do 3 / 8), which will give you the floating-point equivalent of
the fraction, which can then be added to the integer (giving 20.375).
cheers,
barneyb
On 7/17/07, Che Vilnonis <[EMAIL PROTECTED]> wrote:
>
Try:
var num = 20.0;
var frac = 3/8;
var DBWTemp = (num + frac);
document.write(DBWTemp);
Should work.
..
Ben Nadel
Certified Advanced ColdFusion MX7 Developer
www.bennadel.com
Need ColdFusion Help?
www.bennadel.com/ask-ben/
-Original Message-
From: Che Vilnon
take 3/8 out of quotes. it's not a string. it's a number.
you'll get 20.375.
or were you looking for 20 3/8?
On 7/17/07, Che Vilnonis <[EMAIL PROTECTED]> wrote:
> Looking to add an integer and a fraction. How do I do this with Javascript?
> Thanks, Che!
>
>
> var num = 20;
> var frac = "3/8";
9 matches
Mail list logo