This article describes the rounding problem of JS implementing the n-digit decimals. Share it for your reference, as follows:
//The number is rounded (retaining n-digit decimal places) getFloat = function (number, n) { n = n ? parseInt(n) : 0; if (n <= 0) return Math.round(number); number = Math.round(number * Math.pow(10, n)) / Math.pow(10, n); return number; };/*//Usage example: alert(getFloat(2.085,2));//Get 2.09*/For more information about JavaScript related content, please check out the topics of this site: "Summary of JavaScript Mathematical Operation Usage", "Summary of JSON Operation Skills in JavaScript", "Summary of JavaScript Switching Special Effects and Skills", "Summary of JavaScript Search Algorithm Skills", "Summary of JavaScript Animation Special Effects and Skills", "Summary of JavaScript Errors and Debugging Skills", "Summary of JavaScript Data Structures and Algorithm Skills" and "Summary of JavaScript Traversal Algorithm and Skills"
I hope this article will be helpful to everyone's JavaScript programming.