Learn and Learn

Learn And Learn - great place for tutorials, references and how-to

GoLang – Find Integer Value – Trunc() Function – Examples & Explanation

Trunc() function is used to find the integer value of the given input (x – parameter) in Go language. The standard math library/package of Go programming language has Trunc() function.

Syntax of Trunc() Function in Go Language

The syntax of Trunc() function in Go Language is:

Note: float64 is a data type in Go language which has IEEE-754 64-bit floating-point numbers.
Special cases are:
Trunc(±0) = ±0
Trunc(±Inf) = ±Inf
Trunc(NaN) = NaN

 

Parameters of Trunc() Function in Go Language

x – Where x is any Valid float64 Input value. This parameter is required.

 

Error Handling

If the x parameter is not a number (numeric value) Trunc() function returns an error .
If there is no argument (x – input value) passes to the function, then the compiler will produce an error.

 

Return Value of Trunc() Function in Go Language

Trunc() function will returns the integer value of the given input(x – parameter).

 

GoLang Trunc() Function Example 1


Output:
-1

 

GoLang Trunc() Function Example 2


Output:
4

 

GoLang Trunc() Function Example 3


Output:
18

 

Loading...
LearnAndLearn.com © 2018 - All rights reserved