Round<\/strong> method that can be used to round a number. It returns the nearest integer value.<\/p>\n\n\n\nBelow is the signature of the function. It takes input a float and also returns a float.<\/p>\n\n\n\n
func Round(x float64) float64<\/code><\/pre>\n\n\n\nSome special cases of Round function are<\/p>\n\n\n\n
Round(\u00b10) = \u00b10<\/li> Round(\u00b1Inf) = \u00b1Inf<\/li> Round(NaN) = NaN<\/li><\/ul>\n\n\n\n<\/span>Code:<\/strong><\/span><\/h1>\n\n\n\npackage main\n\nimport (\n \"fmt\"\n \"math\"\n)\n\nfunc main() {\n res := math.Round(1.6)\n fmt.Println(res)\n\n res = math.Round(1.5)\n fmt.Println(res)\n\n res = math.Round(1.4)\n fmt.Println(res)\n\n res = math.Round(-1.6)\n fmt.Println(res)\n\n res = math.Round(-1.5)\n fmt.Println(res)\n\n res = math.Round(-1.4)\n fmt.Println(res)\n\n res = math.Round(1)\n fmt.Println(res)\n}<\/code><\/pre>\n\n\n\nOutput:<\/strong><\/p>\n\n\n\n2\n2\n1\n-2\n-2\n-1\n1<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"Table of Contents OverviewCode: Overview math package of GO provides a Round method that can be used to round a number. It returns the nearest integer value. Below is the signature of…<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","footnotes":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false},"categories":[1],"tags":[4,219,222],"class_list":["post-1821","post","type-post","status-publish","format-standard","hentry","category-tech","tag-golang","tag-math","tag-round"],"yoast_head":"\n
Round a number in Go (Golang) - Welcome To Golang By Example<\/title>\n \n \n \n \n \n \n \n \n \n \n \n \n \n\t \n\t \n\t \n