locked
How to transfer a string to double such as "12.6533" to 12.6533 in javascript?

    Question

  • How to transfer a string to double such as "12.6533" to 12.6533 in javascript?

    Tuesday, November 14, 2006 11:24 AM

Answers

  • Javascript is not Java, it's a different thing. In .NET you have JScript compiler (ECMAScript standardized [by ECMA] version of JavaScript) and J# compiler (for Java)

    I suppose in JScript you can directly assign a string to a double or do a cast maybe

    d=(double)s;

    Tuesday, November 14, 2006 8:12 PM

All replies

  • Javascript is not Java, it's a different thing. In .NET you have JScript compiler (ECMAScript standardized [by ECMA] version of JavaScript) and J# compiler (for Java)

    I suppose in JScript you can directly assign a string to a double or do a cast maybe

    d=(double)s;

    Tuesday, November 14, 2006 8:12 PM
  • Try

    parseFloat("12.6533");

    it even works on obscure strings like:

    parseFloat("12.4 px") -> 12.4
    Saturday, July 28, 2007 1:57 PM