473,774 Members | 2,218 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Convert to Double(cDbl) in JavaScript

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
3 63107
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(valu e). 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/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Aug 21 '06 #2
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(otherVal ue);
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
JRS: In article <11************ **********@i42g 2000cwa.googleg roups.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.c om/faq/>? JL/RC: FAQ of news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Aug 22 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
14634
by: Danny | last post by:
I am new to java/javascript. I wrote javascript to proces a cookie. I don't like that fact that the code is visible to all. Can I create a java application that resides on the server and call it this way the code will be hidden? How can a prepare it? It is an apache unix server. Thanks in advance
4
9669
by: D Newsham | last post by:
Hi, This javascript creates a table that has a header and side column that do not move while scrolling through the table. I need to convert this to vb script. Can anybody help, or do you have code in vb (asp) that would do the same thing? <html> <head> <title>Scrolling Grid Demo</title>
5
5631
by: Robin Johnson | last post by:
Hi, I've written an engine in Javascript for running text adventure games on a web page: http://www.robinjohnson.f9.co.uk/adventure/hamlet.html (That's the only game I've written with it so far, and a version of the engine that is slightly less sophisticated than my development copy, which has cleaner code and a more authentic Infocom-style scrolling display, but I digress.)
1
2535
by: sathyan8294 | last post by:
what is websites for convert javascript to vbscript?
7
17382
by: maria80e | last post by:
Is it possible to convert javascript(.js) file as exe or dll? Regards, Maria prabudass E
7
4232
by: deepthi230 | last post by:
how can i convert a javascript string to xml string?
2
4500
by: David | last post by:
Hey can anyone help me convert a javascript array into a ruby array. Ive been struggling with this since friday to no avail. This is the function with the ajax.request call that is supposed to convert the array using JSON, but I keep getting a 422(Unprocessable Entity) error. Im not sure what is wrong. function test() { for(i=1;i<22;i++){ if (document.getElementById(i+'d').className ==
2
7766
by: murugavelmsc | last post by:
Hi, i have a javascript code. I want to convert into VBscript. pls help me Javascript Code:
5
4473
by: rmartine28 | last post by:
i am looking to post something in myspace profile that is java but their system doesn't allow java script, can any one tell me how to convert a java script into htlm ?
0
9621
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10106
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9915
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7463
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5484
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4014
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3611
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2852
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.