Go Float Data Type

Float data types in Go are designed for storing both positive and negative numbers that include a decimal point. These can represent numbers such as 12.75, -3.14, or 98765.4321.

Tutorials dojo strip



In Go, float comes in two variations:

TypeSizeRange
float3232 bits-3.4e+38 to 3.4e+38
float6464 bits-1.7e+308 to +1.7e+308

Tip: If a specific float type is not defined, the default type in Go will be float64.




The float32 Keyword

The float32 type is capable of storing numbers within a more restricted range compared to float64.

Example: Declaring Variables of Type float32
Go




The float64 Keyword

The float64 type is capable of storing significantly larger numbers compared to float32.

Example: Declaring Variables of Type float64
Go




Choosing Between Float Types

Selecting the appropriate float type depends on the range and precision of the value that needs to be stored.

Example: Out-of-Range Error for float32
Go

Output:

Go

Tutorials dojo strip