• Sun 2019.08.11


    "If the fractional portion of the argument is greater than 0.5, the argument is rounded to the integer with the next higher absolute value. If it is less than 0.5, the argument is rounded to the integer with the lower absolute value. If the fractional portion is exactly 0.5, the argument is rounded to the next integer in the direction of +8. Note that this differs from many languages' round() functions, which often round this case to the next integer away from zero, instead giving a different result in the case of negative numbers with a fractional part of exactly 0.5."

    While rounding towards positive infinity does work for negative numbers, it is not rounding
    correctly for exact 0.5 values.

    >console.log(Math.round(-100.6), Math.round(-100.4), Math.round(-101.5), Math.round(-100.5));
    -101 -100 -101 -100
    >console.log(Math.round(100.6), Math.round(100.4), Math.round(101.5), Math.round(100.5));
    101 100 101 100

    Correct values
    > -101 -100 -101 -100
    > 101 100 102 101

      VERSION: "2v04",
      GIT_COMMIT: "3956264e",


    Had a thought, could this anomaly be related to the floating point number of digits to right of zero not matching different browsers and node.js output? hmmmm. . . .

    test files #1

    EDIT: Tue 2019.08.20

    see snippet that may be helpful in resolving this


Avatar for Robin @Robin started