function roundSmart(value, decimals = 3) { return parseFloat(value.toFixed(decimals)); }
Use toFixed and you can give it a number of decimals you want to round to. It will cap at that many. If there are fewer then it wont matter.
toFixed