PDA

Click to See Complete Forum and Search --> : decimal cases



r-cube
04-02-2002, 09:07 PM
Hi,

I need a problem with dynamic text filds to display decimal cases.

My function is:

function decimal (result) {
final = int(result*100)/100;
var dec = (final-(parseInt(final)));
if (dec == 0) {
final = (String(parseInt(final))+".00");
}
if ((length(dec))<4) {
final = (String(parseInt(final))+"."+(dec*10)+"0");
}
return (final);
}

I have looped objects that re-display the values to text filds, but always when the second case after the "." is zero , the second case is not displayed in the result.

Should someone help me?

thanks

tonypa
04-03-2002, 10:08 AM
Not too pretty function, but it works:



function decimal (mynumber) {
var dec = mynumber.slice(0, mynumber.indexOf(".", 0)+2+1);
if (mynumber.indexOf(".", 0) == mynumber.length-2 and mynumber.indexOf(".", 0)<>-1) {
dec = dec+"0";
}
if (mynumber.indexOf(".", 0) == -1) {
dec = dec+".00";
}
if (mynumber.indexOf(".", 0) == mynumber.length-1) {
dec = dec+"00";
}
if (mynumber.length==0) {
dec = "0.00";
}
return (dec);
}


Hope you can use this :)