Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8923747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:13:10+00:00 2026-06-15T07:13:10+00:00

Possible Duplicate: Is JavaScript’s Math broken? I wrote some simple C# code that runs

  • 0

Possible Duplicate:
Is JavaScript’s Math broken?

I wrote some simple C# code that runs Python code dynamically (already implemented):

string code = @"100 * 2 + 4 / 3";
ScriptEngine engine = Python.CreateEngine();
ScriptSource source = engine.CreateScriptSourceFromString(code, SourceCodeKind.Expression);
int res = source.Execute<int>();
Console.WriteLine(res);

And then I thought about Javascript, and that there are core differences between C# and JS. For example:

In JS:

var t=1.02+1.01 = 2.0300000000000002;

And then I tried this via Jint:

var script = @"
  function add( ) {
    return 1.02 + 1.01;
  };
  return add();";
  var result = new JintEngine().Run(script);
  Console.WriteLine(result);

The result was:

enter image description here

Maybe I don’t see the whole picture, but if a programmer on the other side of the world sends me his script file, I (and him) expect the result to be consistent! (Let’s ignore the problematic base 2 representation for now, I’m talking about consistency).

If I was mistaken, in what scenario would I use running other code on .Net? (I will have to be very very suspicious for every line of code…)

Am I right ?

another Example :

   var script = @"
                               function show( )
                               {
                                      return  parseInt('123asd'); //in js it's 123
                               };
                               return show();";

                var result = new JintEngine().Run(script);
                Console.WriteLine(result);

result :

enter image description here

How can I trust a script to yield the same expected result ? ( or am I getting this whole situation wrong…?)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T07:13:11+00:00Added an answer on June 15, 2026 at 7:13 am

    I don’t see any “inconsistency”. That’s just how floating point numbers work!

    1) The value – by definition – is seldom “exact”

    2) The representation (e.g. from Printing out to a string) can be totally misleading if you try to print out more digits than your value has precision 🙂

    Sample C code

    #include <stdio.h>
    
    int 
    main ()
    {
      double d = 1.02 + 1.01;
      float f = 1.02 + 1.01;
      printf ("d=%lf, f=%f\n", d, f);
      printf ("d=%25.20lf, f=%25.20f\n", d, f);
      return 0;
    }
    

    Sample output:

    d=2.030000, f=2.030000
    d=   2.03000000000000020000, f=   2.02999997138977050000
    

    Excellent article:

    • What Every Computer Scientist Should Know About Floating Point Arithmetic

    Finally, please read this discussion:

    • Is floating point math broken?

    The problem is NOT Python, it’s NOT C#, it’s NOT Javascript.

    I assure you 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Is JavaScript's Math broken? Strange result with floating point addition Some simple
Possible Duplicate: Is JavaScript's Math broken? ...and what can I do against that? After
Possible Duplicate: Is JavaScript's Math broken? I've some problems with javascript. If I do
Possible Duplicate: Is JavaScript's Math broken? It returns 5.074999999999999 Why is that? And what
Possible Duplicate: Is JavaScript's Math broken? Adding fractions number yields different result in PHP
Possible Duplicate: Is JavaScript's Math broken? Any ideas as to why: (872.23 + 2315.66
Possible Duplicate: Is JavaScript's Math broken? I have just started playing around with Javascript
Possible Duplicate: Generating random numbers in Javascript I have the following code var randomnumber=Math.floor(Math.random()*101);
Possible Duplicate: Is JavaScript’s Math broken? I'm using Math.round to round the number and
Possible Duplicate: Is JavaScript's Math broken? Suppose, var x = .6 - .5; var

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.