Or maybe cast right after that isNaN check?