JSFiddle - React, Tailwind, and code Playground

HTML

Running.

JavaScript

function addZeroes( num ) {
   var num = Number(num);
   if (String(num).split(".").length < 2 || String(num).split(".")[1].length<=2 ){
          num = num.toFixed(2);
      }
   return num;
}



alert(addZeroes(5));
alert(addZeroes(5.1));
alert(addZeroes(5.11));
alert(addZeroes(5.111));