Convert to Double(cDbl) in JavaScript

R

rishabhshrivastava

Hello All,
How can I convert a value to Double in JavaScript??? In vbscript i
believe its done as

cDbl(Value)

I tried lots of way but getting a value of "NaN".

Any suggestions/ideas will be truely appreciated.

Thanks.
 
L

Lee

(e-mail address removed) said:
Hello All,
How can I convert a value to Double in JavaScript??? In vbscript i
believe its done as

cDbl(Value)

I tried lots of way but getting a value of "NaN".

Any suggestions/ideas will be truely appreciated.

There is no data object named "Double" in Javascript.
What are you really trying to do?


--
 
L

Lasse Reichstein Nielsen

How can I convert a value to Double in JavaScript???

Convert it to a number. All numbers in JavaScript are doubles.

If the value you convert from is a string representation, you
can use either Number(value) or parseFloat(value). The first
requires the value to be a syntactically correct number, whereas
the latter allows trailing garbage.
I tried lots of way but getting a value of "NaN".

Well, success. NaN is a value of the number type (contrary
to its name :). It probably means that the value does not
have the correct format.

/L
 
R

Richard Cornford

Hello All,
How can I convert a value to Double in JavaScript??? In
vbscript i believe its done as

Javascript's only numeric type is an IEEE double precision floating
point number, so if you convert any value into a number that number will
be a double.

The shortest conversion of a value into a number is with the unary plus
operator

var numericVal = (+otherValue);

The most self-documenting is to pass the value as an argument to the
Number object constructor called as a function:-

var numericVal = Number(otherValue);
cDbl(Value)

I tried lots of way but getting a value of "NaN".

That is a different issue, it implies that the value you are trying to
convert is Not a Number (NaN) when type converted into a number. That
may be that it is a string that is not in the correct form to be
converted into a number, or it is an object of some sort that does no
have a - valueOf - method that returns a number primitive or a value
that will type-convert into a number.

Without seeing the input value, and what you are doing with it, it will
not be possible to say.

Richard.
 
D

Dr John Stockton

JRS: In article <[email protected]>
, dated Mon, 21 Aug 2006 15:32:56 remote, seen in
news:comp.lang.javascript, (e-mail address removed) posted :
How can I convert a value to Double in JavaScript??? In vbscript i
believe its done as

cDbl(Value)

I tried lots of way but getting a value of "NaN".

Any suggestions/ideas will be truely appreciated.

Before posting here you should have read the newsgroup and its FAQ,
frequently cited. All of it, but especially sections 2 & 4.21.

All numbers (except when stored as strings) are stored as IEEE Doubles.

To convert a numeric string to a number use unary +, parseInt,
parseFloat, or a purely arithmetic context.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top