create a map with a key of type float in go

Here's an example of how to create a map with a key of type float64 in Go:

main.go
package main

import "fmt"

func main() {
    m := make(map[float64]string)
    m[3.14] = "pi"
    m[2.72] = "e"
    
    fmt.Println(m[3.14]) // prints "pi"
    fmt.Println(m[2.72]) // prints "e"
}
199 chars
13 lines

In this example, we're using the built-in make function to create the map with the float64 type as the key type and string as the value type. Then we're assigning values to the map using floating-point literals. Finally, we're printing the values by accessing the map with the respective keys.

related categories

gistlibby LogSnag