Search code examples
windowstypesnumericjscriptwsh

jscript long or double data type?


I try to declare a variable having Double data type in WSH/Jscript like here: http://msdn.microsoft.com/en-us/library/9h139yks%28v=vs.90%29.aspx

var level : double = 5346.9009;

But on WinXP and win2003 (another OSes not tested) I see this error:

Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.
c:\tmp\t.js(1, 11) Microsoft JScript compilation error: Expected ';'

Also I tried

var level = new Double();

this produces Microsoft JScript runtime error: 'Double' is undefined

How should it be done properly?


Solution

  • Bad and good news.

    First the bad ones. The documentation you are reading is for a "scripting engine" that is part of the NetFramework, not WSH. The WSH JScript documentation is here:

    http://msdn.microsoft.com/en-us/library/hbxc2t98(v=vs.84).aspx

    The good ones. The intrinsic numeric type of JavaScript in the WSH is the same as the double from JScript. More precisely, as the documentation states, it is an 8 bytes IEEE 754, and can hold values from ±1,7976931348623157x10308 to ±5x10-324.

    So, you only need to declare the variable and store inside it the required value:

    var level = 5346.9009;