Skip to content

Latest commit

 

History

History
18 lines (14 loc) · 466 Bytes

convert-string.md

File metadata and controls

18 lines (14 loc) · 466 Bytes

Convert string to different types in Go

Numeric Conversions

The most common numeric conversions are Atoi (string to int) and Itoa (int to string).

i, err := strconv.Atoi("-42")
s := strconv.Itoa(-42)

ParseBool, ParseFloat, ParseInt, and ParseUint convert strings to values:

b, err := strconv.ParseBool("true")
f, err := strconv.ParseFloat("3.1415", 64)
i, err := strconv.ParseInt("-42", 10, 64)
u, err := strconv.ParseUint("42", 10, 64)