I created an app for calculating the amount of change for any money amount (for instance, if i typed 12.48, I would get 0 $20, 1 $10, 0 $5, 2 $1, 1 Quarter, 2 dimes, and 3 pennies) I have the block structure attached.
This is the strange part. When I enter random numbers (for instance 32.91 and 95.16) I'm always a penny short
(I found out that the variable, money was somehow equal to 0.01 after it had displayed the values to me.)
But other random numbers (67.45 and 94.62) displayed all the values correctly, but it made the variable, money equal scientific notation values (2.8311E-15 for 67.45 and 4.5415E-15 for 94.62. The E- values (dont know what to call them) are all around 15 and 16 whenever I come across this instance).
When I found this out, I decided to create an loop that could only be stopped when the value of money was equal to or less than 0. When the loop stopped, it would display the values of quarters, dimes, etc. The values were never displayed. I redesigned the loops in many ways but all came out with the same result.
You can analyze my code and I assure you that all of my display methods are correct (I've checked on multiple occasions). You may even recreate the code if you are unsure. I suspect that it is a bug with the App Inventor program itself. Please tell me if you know anything about this. I will talk with my computer science teacher tomorrow too.
thank you.
This is the strange part. When I enter random numbers (for instance 32.91 and 95.16) I'm always a penny short
(I found out that the variable, money was somehow equal to 0.01 after it had displayed the values to me.)
But other random numbers (67.45 and 94.62) displayed all the values correctly, but it made the variable, money equal scientific notation values (2.8311E-15 for 67.45 and 4.5415E-15 for 94.62. The E- values (dont know what to call them) are all around 15 and 16 whenever I come across this instance).
When I found this out, I decided to create an loop that could only be stopped when the value of money was equal to or less than 0. When the loop stopped, it would display the values of quarters, dimes, etc. The values were never displayed. I redesigned the loops in many ways but all came out with the same result.
You can analyze my code and I assure you that all of my display methods are correct (I've checked on multiple occasions). You may even recreate the code if you are unsure. I suspect that it is a bug with the App Inventor program itself. Please tell me if you know anything about this. I will talk with my computer science teacher tomorrow too.
thank you.
The two screenshots are supposed to be connected in one block of code. I separated them because the block was too large to show in one screenshot.
--
Yikes!! If-then in more than three levels smells trouble. Make some sensible procedures and then try again. Try DoIt on each step then.
Cheers, Ghica.
Cheers, Ghica.
--
This is the strange part. When I enter random numbers (for instance 32.91 and 95.16) I'm always a penny short
(I found out that the variable, money was somehow equal to 0.01 after it had displayed the values to me.)
But other random numbers (67.45 and 94.62) displayed all the values correctly, but it made the variable, money equal scientific notation values (2.8311E-15 for 67.45 and 4.5415E-15 for 94.62. The E- values (dont know what to call them) are all around 15 and 16 whenever I come across this instance).
AI2 stores dollars and cents as a IEEE754 floating point number, with a binary mantissa.
The mantissa stores approximately 15 decimal digits worth of precision.
Binary mantissas see decimal fractions like 0.1 as infinitely repeating decimals, hence the loss of accuracy.
I suggest multiplying your input by 100 and then rounding it, to get an integer number of pennies.
ABG\
(see Math section)
댓글 없음:
댓글 쓰기