This is a creation in Article, where the information may have evolved or changed.
the constants supported by the go language are character, String, Boolean, and numeric.
Use the const keyword to define constants.
where you can have a var statement, you can have a const statement.
constant expressions can be computed with arbitrary precision. Constants are of no type unless there are statements given, such as coercion of type conversions.
numeric constants are automatically added to the type when the context requires it. For example, variable assignment or function call. The math in this example. Sin (n), sin
The function requires a int64 type, and n is automatically converted to int64.
Plain Text Code ?
123456789101112 |
package main
import " FMT "
import " math "
const s string = " constant "
func main () {
    
fmt. Println (s)
    
const n = 500000000
    
const d = 3e20 / n
    
fmt. Println (d)
    
fmt. PRINTLN (Int64 (d))
    
fmt. Println (Math. Sin (n))
}
|
$ go Run constant.go
constant
6e+11
600000000000
-0.28470407323754404
Original link:Https://gobyexample.com/constants