Convert to Double(cDbl) in JavaScript

Discussion in 'Javascript' started by rishabhshrivastava@gmail.com, Aug 21, 2006.

  1. Guest

    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, 2006
    #1
    1. Advertising

  2. Lee Guest

    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?


    --
     
    Lee, Aug 21, 2006
    #2
    1. Advertising

  3. 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 -
    DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
    'Faith without judgement merely degrades the spirit divine.'
     
    Lasse Reichstein Nielsen, Aug 22, 2006
    #3
  4. 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.
     
    Richard Cornford, Aug 22, 2006
    #4
  5. JRS: In article <>
    , dated Mon, 21 Aug 2006 15:32:56 remote, seen in
    news:comp.lang.javascript, 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.htm> jscr maths, dates, sources.
    <URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
     
    Dr John Stockton, Aug 22, 2006
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Web learner

    from List <double> to double[]

    Web learner, Apr 25, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    485
  2. da Vinci
    Replies:
    5
    Views:
    8,735
    da Vinci
    Jul 31, 2004
  3. Sydex
    Replies:
    12
    Views:
    6,507
    Victor Bazarov
    Feb 17, 2005
  4. Heiko Vogel
    Replies:
    3
    Views:
    565
    Method Man
    Sep 14, 2004
  5. Laphan

    Diff between CSng and CDbl

    Laphan, Nov 18, 2005, in forum: ASP General
    Replies:
    3
    Views:
    139
    Patrice
    Nov 18, 2005
Loading...

Share This Page