How to round a number to one decimal place

I needed to round numbers to one decimal place in a project. It’s important to maintain precision and avoid unexpected side effects, especially in financial calculations. What methods do you use for reliable rounding in JavaScript?

To round to one decimal place, I most often use toFixed(1). It returns a string, but you can then use parseFloat() to convert it back to a number. For financial calculations, it’s best to use a BigDecimal library, such as decimal.js.

I know that to reliably round a number to 1 decimal place in JavaScript, you can use a method using Math.round and a multiplier. This avoids some issues with floating-point precision. A detailed discussion of this approach, including rounding up, can be found here https://hasty.dev/javascript/ceil-1-decimals