개요
기본 자료형과 문자열간의 변환을 구현한 패키지
예제
코드
package main
import (
"strconv"
)
func main () {
println ( strconv . Itoa ( 123 ))
println ( strconv . Atoi ( "123" ))
println ( strconv . FormatBool ( true ))
println ( strconv . ParseBool ( "true" ))
println ( strconv . FormatInt ( 12345 , 10 ))
println ( strconv . ParseInt ( "12345" , 10 , 64 ))
println ( strconv . FormatInt ( - 12345 , 10 ))
println ( strconv . ParseInt ( "-12345" , 10 , 64 ))
println ( strconv . FormatUint ( 12345 , 10 ))
println ( strconv . ParseUint ( "12345" , 10 , 64 ))
println ( strconv . FormatFloat ( 1.1 , 'f' , - 1 , 64 ))
println ( strconv . ParseFloat ( "1.1" , 64 ))
}
실행 결과
123
123 ( 0x0,0x0)
true
true ( 0x0,0x0)
12345
12345 ( 0x0,0x0)
-12345
-12345 ( 0x0,0x0)
12345
12345 ( 0x0,0x0)
1.1
+1.100000e+000 ( 0x0,0x0)
Tags:
Atoi ,
FormatBool ,
FormatFloat ,
FormatInt ,
FormatUint ,
Itoa ,
ParseBool ,
ParseFloat ,
ParseInt ,
ParseUint ,
strconv
Categories:
Go ,
programming-language
Updated: December 28, 2022