How to round using ROUND HALF UP. Rounding mode that most of us were taught in grade school

11,530

The Math.round() will round up when n >= 5 else round down

Examples:

Math.round(20.49);// 20

Math.round(20.5);// 21

Math.round(-20.5);// -20

Math.round(-20.51);// -21

Note: The examples were taken from the link above

Native functions don't bite, my advice is to try to always try to use them whenever possible. They are faster and do the same job after all

Share:
11,530
eros
Author by

eros

University student

Updated on September 11, 2022

Comments

  • eros
    eros almost 2 years

    how to round using ROUND HALF UP in javascript? I am using Prototype JavaScript framework version 1.5.1_rc3, so I prefer to use it if available. If not, I appreciate also if you share it.

    Any guidance is appreciated.