Hi guys. Im learning go, and i just did something that i can't get. Could someone tell me why this float math returns some number like "860.9000000000001" ?
package main
import "fmt"
type CheckingAccount struct {
owner string
agenceNumber int
account int
ballance float64
}
func (sender *CheckingAccount) Transfer(recipient *CheckingAccount, transferValue float64) bool {
if transferValue > sender.ballance || transferValue <= 0 {
return false
}
sender.ballance -= transferValue
recipient.ballance += transferValue
return true
}
func main() {
account := CheckingAccount{
owner: "Antonio",
agenceNumber: 0567,
account: 123456,
ballance: 1380.90,
}
account2 := CheckingAccount{
"Antonio",
0567,
123456,
1380.90,
}
fmt.Println(account, account2)
account.Transfer(&account2, 520.)
fmt.Println(account, account2)
}
output:
{Antonio 375 123456 1380.9} {Antonio 375 123456 1380.9}
{Antonio 375 123456 860.9000000000001} {Antonio 375 123456 1900.9}