var cash, change, bet int64 : bet = cash/4 // change is 0,1,2,3 meaning 0/4, 1/4, 2/4, 3/4 dineros or zlottys or whatever change = cash - 4*bet // or, change = cash%4
// choose one of these if change>0{ bet++ // a: round up means 1/4 and 2/4 and 3/4 go to 1 } // ...or... if change>=2{ bet++ // b: round up means 2/4 and 3/4 go to 1 } cash = cash - bet once you understand the above compare to these versions: bet = (cash+3)/4 // this is Kurtis's advice, mode (a) cash = cash - bet ...or... bet = (cash+2)/4 // this is mode (b) cash = cash - bet On Tue, Aug 4, 2020 at 3:37 AM Martin Møller Skarbiniks Pedersen < traxpla...@gmail.com> wrote: > On Sun, Aug 2, 2020 at 2:09 PM Martin Møller Skarbiniks Pedersen < >> traxp...@gmail.com> wrote: >> >>> I have written my first little piece of Go-code. >>> However it took some time and code for me to divide a int64 by 4 and >>> round down. >>> >>> [...] >>> var bet int64 >>> bet = int64(math.Ceil(float64(cash)/float64(4))) >>> >>> > On Sunday, 2 August 2020 23:25:23 UTC+2, Kurtis Rader wrote: >> >> In addition to Jake's question regarding whether you want to round up or >> down I'll point out there isn't any to cast to float64 and back to int64. >> If you want to "round down" just divide by four. If you want to "round up" >> add one less than the divisor before dividing; e.g., bet := (cash + 3) / >> 4. Notice the ":=" which avoids the need for the "var bet int64" statement. >> > > > OK. Good idea. But what is I need to integer divide with a variable and > not the number 4? > > Cheers > Martin > > > > -- > 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+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/golang-nuts/025665ff-21eb-4139-93c6-57f1adfc5cc9o%40googlegroups.com > <https://groups.google.com/d/msgid/golang-nuts/025665ff-21eb-4139-93c6-57f1adfc5cc9o%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- *Michael T. jonesmichael.jo...@gmail.com <michael.jo...@gmail.com>* -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CALoEmQy2mSaMnyrAjJvH3QQXONjSgOnRLKodN8moFord36U5iw%40mail.gmail.com.