before easy. This is just a rounding operation.
var before = function(n) { return Math.floor(n); };
after harder without string handling. I mean, how would you deal with after(Math.PI) ? You cannot hold an integer with an infinite number of digits.
But with some string processing, it's simple, just know that it will not be exactly because of the wonders of floating point math.
var after = function(n) { var fraction = n.toString().split('.')[1]; return parseInt(fraction, 10); };
source share