CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Threaded View

  1. #2
    Join Date
    May 2002
    Posts
    10,943

    Re: duplicating javscript math errors

    This is because the long datatype is not existent in JavaScript. For that, you will have to use an additional library. Just in case you don't want to go there, the included files are also attached.

    Code:
    <div style="font: 14px monospace;">
    <script type="text/javascript" src="mathcontext.js"></script>
    <script type="text/javascript" src="bigdecimal.js"></script>
    <script type="text/javascript">
    for (var i = 1; i <= 9; i++) {
      var firstNumber = parseInt(i + "20575940379279400", 10);
      var secondNumber = 13510798882111488;
      var finalNumber = parseInt(firstNumber, 10) + secondNumber;
    
      var v1 = new BigDecimal(firstNumber.toString());
      var v2 = new BigDecimal(secondNumber.toString());
      finalNumber = v1.add(v2);
    
      document.write("&nbsp; " + firstNumber + "<br />+&nbsp; " + secondNumber);
      document.write("<br />--------------------<br />&nbsp; " + finalNumber)
      document.write("<br /><br />");
    }
    </script>
    </div>
    Attached Files Attached Files
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured