Corrected bug in substr() invocation and switched from atoi() to atof()