how can I solve it 2 decimal places float32 with fmt.Println()

108 views
Skip to first unread message

Tareq Ibna

unread,
Mar 4, 2021, 11:31:57 AM3/4/21
to golang-nuts
package main 
import "fmt"

func main(){

     //I want to solve this peoblen with fmt.Println()  please help.
 

var a, b ,c float32

fmt.Println(" Enter 1st number:" )
fmt.Scan( &a)

fmt.Println(" Enter 2nd number:" )
fmt.Scan( &b)
c= a/b 

       fmt.Printf(" %.2f", c) 




}

jake...@gmail.com

unread,
Mar 4, 2021, 11:52:53 AM3/4/21
to golang-nuts
Can you tell us what the problem is that you want to solve? The code3 seems to run just fine.

Levieux Michel

unread,
Mar 4, 2021, 6:04:17 PM3/4/21
to Tareq Ibna, golang-nuts
If the problem is that you want to have a newline at the end of your answer you can just put "\n" at the end of your string. If you want to do the same using fmt.Println, you can check fmt.Sprintf :)

Otherwise indeed your issue is not that clear to me. 

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/00dac027-05d2-4ef8-a123-cf438981d849n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages