Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Deposit and Withdraw with float64
package main
import (
"fmt"
)
var balance float64 = 0
func main() {
deposit(.1)
deposit(.2)
if balance, ok := withdraw(0.30000000000000004); ok {
fmt.Println(balance)
}
}
func deposit(v float64) {
balance += v
}
func withdraw(v float64) (float64, bool) {
if v <= balance {
balance -= v
return v, true
}
return 0, false
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.