Get the App
SLTechnology News&Howtos  ›  Development  › 

How to convert an integer to a floating-point type and calculate the result in Go language

Shulou Source: shulou.com Published: 2022-06-01 02:26:46 09月21日 Update

This article introduces the relevant knowledge of "how to convert integers into floating-point types in Go language and calculate the results". In the operation of actual cases, many people will encounter this dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Type conversion is used to convert a variable of one data type to another. The basic format of Go language type conversion is as follows:

Type_name (expression)

Type_name is the type and expression is the expression.

Example

In the following example, an integer is converted to a floating-point type, the result is calculated, and the result is assigned to a floating-point variable:

Package main

Import "fmt"

Func main () {

Var sum int = 17

Var count int = 5

Var mean float32

Mean = float32 (sum) / float32 (count)

Fmt.Printf ("value of mean is:% f\ n", mean)

}

The output of the above example is as follows:

The value of mean is 3.400000, "how does the Go language convert integers to floating-point types and calculate the results?" Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Results types floating points languages variables examples content more knowledge output practicality learning and then lieutenant general dilemma reality situation data article format Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB macOS Shulou Information Docker OPPO Reno