Friday, July 11, 2014

round decimals back to integers in JavaScript

Example:

$('#a').attr("style", "background-position: " + Math.round((b - (c + 40)) / 2) + "px 0px;");

 
 

Also note: Math.ceil always rounds decimals up to the next integer and Math.floor always rounds decimals down to the next integer.

No comments:

Post a Comment