Initial JS version attempt
Fix rounding function