type 비교 (whether string or float64) > IT 기술백서

IT 기술백서

직접 알아내거나 검색하기 귀찮아서 모아 둔 것

Go lang | type 비교 (whether string or float64)

본문

1. 첫번째 방법

[code]

str := 129.29438455

if reflect.TypeOf(str).String() != "string" {

  //

}

[/code]

 

2. 두번째 방법

[code]

a := "34.1718000440"


switch a.(type) {

case float64:

  fmt.Println("This is float64")

case string:

  fmt.Println("This is string")

default:

  fmt.Println("unknown")

[/code]

댓글 0개

등록된 댓글이 없습니다.

Menu