create template function for toInt()

@jxwuyi 
ready for review