By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,703 Members | 1,116 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,703 IT Pros & Developers. It's quick & easy.

Convert to Double(cDbl) in JavaScript

P: n/a
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.

Aug 21 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
ri****************@gmail.com writes:
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
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Aug 21 '06 #2

P: n/a
ri****************@gmail.com wrote:
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.
Aug 21 '06 #3

P: n/a
JRS: In article <11**********************@i42g2000cwa.googlegroups .com>
, dated Mon, 21 Aug 2006 15:32:56 remote, seen in
news:comp.lang.javascript, ri****************@gmail.com 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.

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4
<URL:http://www.jibbering.com/faq/>? JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Aug 22 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.