Format numbers with separators based on locale

Fixes #593.