• 0 Vote(s) - 0 Average
• 1
• 2
• 3
• 4
• 5
 Problem with value of a double Matthew Member Posts: 58 Threads: 19 Joined: Mar 2013 05-20-2013, 04:23 AM Hello, I have a macro that automates the playing of roulette and I am trying to improve the speed of bet placement by having the macro determine the correct chip size based on the bet amount. This works well, however if the remaining bet is less than 1 and not equal to one of the unit sizes, the number is not accurately calculated and hence the last bet is not correct. Macro Calulate Bet Code: ```ARRAY(double) unit unit.create(6) unit=0.10 unit=0.50 unit=1 unit=5 unit=25 unit=100 double nextBet=9.50 int inc double chipValue int chipAmount double chipAmount1 double Remainder=nextBet rep ,for inc 0 unit.len ,,if unit[inc]>=Remainder ,,,if unit[inc]=Remainder ,,,,chipValue=unit[inc] ,,,,break ,,,chipValue=unit[inc-1] ,,,break ,,else ,,,chipValue=unit[unit.len-1] ,chipAmount=Remainder/chipValue ,Remainder=Remainder-(chipAmount*chipValue) ,mes chipValue ,mes chipAmount ,mes Remainder ,if Remainder=0 ,,break ,``` In the above, if nextBet is 9.5 it calculates each unit and number of units fine and exits the loop correctly betting .50 as last bet of one unit. However if it is 9.2 it fails to determine the remainder correctly on the last step of the loop and returns 0.199999999 instead of .20, thus messing up the last bet. I am sure this is an error with the variable type but not sure how to work around it? Thanks kindly Matt Reply Reply Gintaras Administrator Posts: 11,043 Threads: 128 Joined: Dec 2002 05-20-2013, 02:21 PM It is common problem in floating point calculations in all languages. Macro Macro2033 Code: ```,Remainder=Round(Remainder 2) ;;0.1999999... -> 0.20 ,out F"{chipValue} {chipAmount} {Remainder}"``` Reply Reply Matthew Member Posts: 58 Threads: 19 Joined: Mar 2013 05-20-2013, 10:02 PM Gintaras Wrote:It is common problem in floating point calculations in all languages. Macro Macro2033 Code: ```,Remainder=Round(Remainder 2) ;;0.1999999... -> 0.20 ,out F"{chipValue} {chipAmount} {Remainder}"``` Oh that is perfect! Thanks I feel like such a dill as I looked at Round but had the syntax wrong - thankyou! Reply Reply « Next Oldest | Next Newest »

Forum Jump:

Users browsing this thread: 1 Guest(s) 