Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,900 questions

51,831 answers

573 users

How to round a number to nearest int when casting float to int in Go

1 Answer

0 votes
package main 
   
import ( 
    "fmt"
) 
   
func main() { 
	f1 := 2.2
 	res_1 := int(f1 + 0.5) 
	
	f2 := 2.5
    res_2 := int(f2 + 0.5) 
	
	f3 := 2.8
    res_3 := int(f3 + 0.5) 
   
    fmt.Printf("%d\n", res_1) 
    fmt.Printf("%d\n", res_2) 
    fmt.Printf("%d\n", res_3) 
} 
 
 
 
/*
run:
 
2
3
3
 
*/

 



answered Aug 4, 2020 by avibootz

Related questions

1 answer 45 views
1 answer 156 views
156 views asked Aug 4, 2020 by avibootz
1 answer 207 views
207 views asked Oct 17, 2020 by avibootz
1 answer 135 views
135 views asked May 26, 2020 by avibootz
1 answer 50 views
1 answer 50 views
...