[Javascript] Truncating floating point values

Mckinney, Lori K lkmckinn at ingr.com
Thu Mar 28 10:49:17 CST 2002


Cutter,

Can you do something like this?  

function fixAtTwo(anynum) 
{
	var numStr=anynum.toString();
	var decPos = numStr.indexOf(".");	
	if ( decPos == -1 )
		return numStr + ".00";
	else
	{
		// add two zeros to get at least two digits at the 
		// end of the string in case it ends at the decimal
		numStr += "00";	
		return numStr.substr(0,decPos+3);
	}
}

Hope that works for you.  

Lori

P.S. By the way, hope your little girl is doing well.

-----Original Message-----
From: Cutter Bl [mailto:cutterbl at hotmail.com]
Sent: Thursday, March 28, 2002 10:27 AM
To: Javascript at LaTech.edu
Subject: [Javascript] Truncating floating point values


How do you truncate a floating point value at a specific decimal place? I'm 
not trying to round the number, just cut it off after two decimal places...

Cutter
http://www.falcon-knives.com

_________________________________________________________________
Join the world's largest e-mail service with MSN Hotmail. 
http://www.hotmail.com

_______________________________________________
Javascript mailing list
Javascript at LaTech.edu
https://lists.LaTech.edu/mailman/listinfo/javascript



More information about the Javascript mailing list