-
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
-
Not too pretty function, but it works:
Code:
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 :)