1 <!DOCTYPE HTML>2 <HTMLLang= "en">3 <Head>4 <MetaCharSet= "UTF-8">5 <title>Format-number</title>6 </Head>7 <Body>8 <inputtype= "text"ID= "Input"><inputtype= "text"ID= "Output">9 </Body>Ten <Script> One varIPT=document.getElementById ('input'); A varopt=document.getElementById ('Output'); - Ipt.oninput=function(){ - Opt.value=Zero ( This. value); the } - functionZero (num) { - varStr=num.tostring (); - if(Str.indexof (".")==-1){ + returnNum+". XX"; - }Else{ + varLen=Str.indexof ("."); A if(Str.slice (Str.indexof ('.'). Length== 2){ at returnNum+"0" - }Else if(Str.slice (Str.indexof ('.'). Length> 3){ - varLen=Str.indexof ("."); - varstr1=Str.slice (0, Len); - varLeng=Str1.length+3; - varstr2=Str.slice (0, Leng); in returnNumber (STR2); - }Else{ to returnnum; + } - } the } * </Script> $ </HTML>
javascript-zero-Reserved 2 decimal places