I want a Javascript code which convert input integer to money format.
ex: say my input is 20 it should show me 20.00. If my input is 20.45,it should shoe me the same value as 20.45.
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Niradhip ChakrabortyPosted Jun 4, 2008, 4:50 AM
Try it:
function formatAsMoney(ObjVal)
{
//Obj.value = formatAsMny(Obj.value)
mnt = ObjVal;
mnt -= 0;
mnt = (Math.round(mnt*100))/100;
ObjVal = (mnt == Math.floor(mnt)) ? mnt + '.00' : ( (mnt*10 == Math.floor(mnt*10)) ? mnt + '0' : mnt);
if (isNaN(ObjVal)) {ObjVal ="0.00";}
return ObjVal;
}
Paresh DesaiPosted Jun 4, 2008, 4:20 AM
HTML Syntext