View Single Post
Old 11-21-2002, 03:41 PM   #4 (permalink)
abc123
bloomberg
 
abc123's Avatar
 
Join Date: Jun 2002
Location: bloomberg
Posts: 263
abc123 is on a distinguished road
Send a message via AIM to abc123 Send a message via Yahoo to abc123
actually i wanted it to a "fixed" two decimal value of 100000 of a cent accuracy, this is how i did it:

Code:
	function t2(v){
		tmpv = v;
		suffix = ""
		do0 = false;
		if(Math.round(v) == v){
			suffix = ".00";
			res = v+suffix;
			return res;
		}else{
			v = v+"";
			tmpy = v.indexOf(".");

			if(tmpy+6 < v.length){
				tmpRem = v.substring(tmpy, tmpy+6);
				tmpz = Math.floor(v);
				return tmpz+".00";
			}

		}

		tmpv = tmpv * 100;
		tmpv = Math.round(tmpv);
		if(tmpv % 10 == 0 || tmpv % -10 == 0){
			do0 = true;
		}
		tmpv = tmpv / 100;
		if(do0){
			tmpv = tmpv + "0";
		}
		return tmpv;
	}
unfortunately, or fortunately, after writing that i discovered this function:

Code:
var x = 16.000000000000001;
alert(x.toFixed(2));
hmm, oh well at least that was only a small section of what i had to do, the code wasn't a waste.
__________________
-- bloomberg.
abc123 is offline   Reply With Quote