Fix off-by-one logic error
Create toFormattedString and test