Golang math.Exp() Function

Golang math.Exp() Function

Golang math.Exp() function is “used to find the e**x, where the base-e exponential of x, where x is the input parameter.” Syntax func Exp(x float64) float64 Parameters x: It is the value of float64 type whose base-e exponential is to be found. An exception to the above statements is when you pass something that is … Read more

Golang math.Dim() Function

Golang math.Dim() Function

Golang math.Dim() function returns the “maximum of x-y or 0.” Syntax func Dim(x, y float64) float64 Parameters x, y: The values to get the maximum of x-y or 0. Return value The Dim() function returns a single value of type float64. This value represents the difference between the two arguments (x-y) and 0. Dim(+Inf, +Inf) … Read more

Golang math.Cbrt() Function

Golang math.Cbrt() Function

Go math.Cbrt() function is “used to find the cubic root of a number.” It accepts one parameter and returns the cube root. Syntax func Cbrt(x float64) float64 Parameters x: It is a value whose cube root value is to be found. Return value The Cbrt() function returns a single value of type float64. This value represents … Read more

Golang math.Round() Function

Golang math.Round() Function - How to Use it

Golang math.Round() function is “used to find the nearest integer, rounding half away from zero”. It takes a floating-point number as an argument and returns the rounded integer value of that number. The returned value is of type float64. Syntax func Round(x float64) float64 Parameters x: The Round() function accepts a floating-point number as an … Read more

How to Convert Rune to String in Golang

How to Convert Rune to String in Golang

To convert a rune to a string, you can “use the string() function.” In Go, a rune is an alias for the int32 type, representing a Unicode code point. package main import “fmt” func main() { r := rune(‘K’) fmt.Println(r) // Convert rune to string s := string(r) fmt.Println(“Rune as string:”, s) } Output 75 Rune … Read more

How to Convert Interface to Struct in Golang

How to Convert Interface to Struct in Golang

To convert an Interface to a Struct in Golang, you can use the “interface.(Struct) method.” Type assertion lets you “specify the desired type and returns the value in that type if the assertion holds”. If the underlying value isn’t of the specified type, it will panic unless you use the two-value form. package main import … Read more

How to Convert JSON to Struct in Golang

To convert a JSON string (or a byte slice containing JSON) to a Go struct, you can “use the json.Unmarshal() function from the encoding/json package.” Go JSON to Struct Here is the step-by-step guide to convert JSON to Struct in Go: Define the struct that matches the expected structure of the JSON data. Convert the … Read more

How to Convert Struct to JSON in Golang

How to Convert Struct to JSON in Golang

To convert a Struct to JSON in Golang, you can “use the json.Marshal() function.” The json.Marshal() function is “used to encode a struct into a JSON-formatted byte slice.” Go Struct to JSON Here are the steps to convert the struct to json in Golang: Define your struct. Create an instance of the struct. Convert the … Read more

How to Convert Uint16 to String in Golang

How to Convert Uint16 to String in Golang

To convert a uint16 value to a string in Go, you can use the “strconv.FormatUint() or strconv.Itoa() function.” Method 1: Using the strconv.FormatUint() function The strconv.FormatUint() function is used to convert unsigned integer values (e.g., uint, uint16, uint32, uint64) to strings. package main import ( “fmt” “strconv” ) func main() { var myUint16 uint16 = … Read more