How about:
function showRounded(val) { var zero = parseInt(val.split('.')[0],10) === 0; return zero ? val.substring(val.indexOf('.')) : val.replace(/^0+/,'') );}console.log(showRounded('000.03')); //=> ".03"console.log(showRounded('900.03')); //=> "900.03"console.log(showRounded('009.03')); //=> "9.03"
Or adjust Álvaro G. Vicario's solution to get rid of leading zero's into:
String(parseFloat("090.03")).replace(/^0+\./, ".")