Don't you have to reset format to undefined if its a number, otherwise you're applying `|| ''` later on, which might not be what you're expecting.