How do you round a number to N decimal places

This is a cursed JavaScript approach. Please just use the one from @fvasco