Syntax of Math.trunc()
See below example doesn’t do any rounding, it simply removes all the digits following the decimal.
Math.trunc() isn’t supported on all platforms yet (namely IE), but you could easily use a polyfill in the meantime.
(Math.round(num * 100) / 100).toFixed(2);
Note that it will round to 2 decimal places, so the input
1.746 will return
Do comment if you have any questions and suggestion on this tutorial.
Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.
OS: Windows 10
Code: HTML 5 Version
Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology & like learning technical.