Tusk Posted October 29, 2010 Share Posted October 29, 2010 I want to use a result for furtherer calculations but only want the whole number and not the decimal portion. In Excel there is a function "=INT(A1)" this ignores the decimal values in cell "A1", e.g. if call "A1=5.345"and I use the following function in cell "A2" "=INT(A1)*3" I get the result "15"How do I do this in JavaScript ?Thanks Link to comment Share on other sites More sharing options...
thescientist Posted October 29, 2010 Share Posted October 29, 2010 you can use javascript's native Math object and use the floor method.http://www.w3schools.com/jsref/jsref_obj_math.asp Link to comment Share on other sites More sharing options...
ShadowMage Posted October 29, 2010 Share Posted October 29, 2010 Math.round() will round the number to the nearest integer, either up or down. floor() rounds down, and ceil() rounds up. Link to comment Share on other sites More sharing options...
dsonesuk Posted October 29, 2010 Share Posted October 29, 2010 or use parseInt which produces the same result as excel int() as math.floor() and as math.ceil() would for floor() and ceiling() in excel.var a = 5.345;var b = parseInt(a)*3; Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.