Digital Precision Control in javaScript

how does the javaScriptde decimal.js library control the accuracy of numbers

function round(x, y) {
  const a = new Decimal(x).round();
  Decimal.set({ precision: 2, rounding: y });
  return a;
}

console.log(round("1235.1235", 1).valueOf()); // 1235

above is the code. I don"t know what the problem is

Mar.02,2021

because js is a weakly typed language, and the number that the computer can read is only 0: 1, some floating-point numbers will be converted to 0: 1 and then calculated, so there will be this problem of loss of precision. There are three ways that I have learned so far:
1.bignumber.js is calculated through this js library;
2. Multiply the number that needs to be operated by the n power of 10, and then go to the n power of 10 after the operation, you can get the exact number;
3. ToFixed (), the number after the operation, but this method also loses precision and is not recommended;
4. Pure hand play, hope to adopt


you didn't say what you wanted.
read the document and feel that the function of round is rounding.
if you want to control the number of digits, use the toExponential, toFixed and toPrecision methods.

x = new Decimal(255.5)
x.toExponential(5)              // '2.55500e+2'
x.toFixed(5)                    // '255.50000'
x.toPrecision(5)                // '255.50'
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b362ac-2bfe5.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b362ac-2bfe5.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?