JSFiddle - React, Tailwind, and code Playground

JavaScript

function precise_round(value, decPlaces){
    var val = value * Math.pow(10, decPlaces);
    var fraction = (Math.round((val-parseInt(val))*10)/10);
    if(fraction == -0.5) fraction = -0.6;

    val = Math.round(parseInt(val) + fraction) / Math.pow(10, decPlaces);
    return val;
}
alert("precise_round(342.0595,3)= >" +precise_round(342.0595,3)+" it's truncating the zero")//it's truncating the zero
alert("precise_round(342.995,2) =>" +precise_round(342.995,2))//it's truncating the zero
alert((342.0595).toFixed(3))
alert((342.0595).toFixed(2))