JS in the tofixed (n) method to round the number to the number of the specified number of decimal digits, Note: This method can only be used for data type numbers, including Float,int. For example:
123.12345.toFixed (2); "123.12" divide the data by using a single statement like this:. Replace (/\d{1,3} (? = (\d{3}) + (\.\d*)? $)/g, ' $&, '). Note: thereplace () method can only work on string types , and our team data is usually divided by the number of decimal divisions, so the data must be converted to a string type before the data is divided into thousands of bits. or use the 123456.1234.toFixed (2) + "" method to convert the data to a string type. For example:123456.1234.toFixed (2). toString (). Replace (/\d{1,3} (? = (\d{3}) + (\.\d*)? $)/g, ' $&, '); "123,456.12"(123456.1234.toFixed (2) + ""). Replace (/\d{1,3} (? = (\d{3}) + (\.\d*)? $)/g, ' $&, '); "123,456.12"Although these 2 methods are very simple, but in the data processing use more, so it is more practical.
How to get 2 decimal places in JS and divide the data into thousands of bits