OneBite.Dev - Coding blog in a bite size

declare a float number in Go

Code snippet on how to declare a float number in Go

  package main

import "fmt"

func main() {
   //Declaring var of type float
   var number float64
   
   //Initiating var
   number = 10.5
   
   fmt.Println("Number is", number)
}

This code snippet shows how to declare and inititate a float number in the Go programming language. Firstly, the code imports the “fmt” package, which stands for formatting and provides functions such as Println.

Next, the code declares a float number as a float64 type of variable. The type float64 is a 64-bit floating-point number used to store decimal numbers with up to 16 digits of precision.

Finally, the number is initiated to a value of 10.5 and printed out with the Println function. The output of the code will be “Number is 10.5”.

go