I am writing a parser and an encoder, and I need to guess the number type that the user supplies in the code. For example, the user inputs 8, without any type cast in code, and i need to convert it to int8
, if I put in 0.5, I get float32
, and if I put, for example, 5182645, I get an int32. Is there any practical way to accomplish that in Go, or should I just write a big if chain?
Aucun commentaire:
Enregistrer un commentaire