It's great that you are helping the community with contributions, but i must be honest that this particular example does seem to be a little long-winded...
function(double value, int snap)
{
return integer(value / snap) * snap;
}
I use this in a little mouse-snapping contribution I added...
http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=285586#Post285586... But it's good to see you are at least trying to work things out for yourself, keep it up.
Thanks, DJB.