Standard library / go/constant
go/constant.ToInt()
Convert an integral representable constant to Int; otherwise return Unknown. Expected stdout: '2 Unknown\n'.
Formal Syntax & Structure
go syntaxgo
func ToInt(x Value) ValueParameters & Attributes
| Name | Type | Description |
|---|---|---|
| x | Value | Input constant or Go value as specified by the function. |
Return Value
Value
Convert an integral representable constant to Int; otherwise return Unknown.
Working Example
Example Snippetgo
package main
import ( "fmt" "go/constant" "go/token")
func main() { fmt.Println(constant.ToInt(constant.MakeFromLiteral("2.0", token.FLOAT, 0)), constant.ToInt(constant.MakeFromLiteral("2.5", token.FLOAT, 0)).Kind())}