Standard library / math

math.Trunc()

Discards fractional part toward zero. Expected stdout: '-3\n'.

Formal Syntax & Structure

go syntaxgo
func Trunc(x float64) float64

Parameters & Attributes

NameTypeDescription
xfloat64First input operand (or sole input if unary).

Return Value

float64

Discards fractional part toward zero.

Working Example

Example Snippetgo
package main
import (  "fmt"  "math")
func main() {  fmt.Println(math.Trunc(-3.9))}
Go Reference