Round-off error (?) in Java cash register code

I am trying to create a program where you enter an how much you owe and how much you pay and then the code returns a JOptionPane message telling you how much of each bill/coin to give.

Example: I owe 14.47 and I pay 20, the return statement will be "five: 1, one: 0, quarter: 2, etc."

I pretty much have the code done however, for some reason the program will give one less penny than is needed. I've determined that it is a round off error, but I have no idea how to solve it or do it any other way.

private double owed;

private double paid;

private ArrayList<Currency> currency;

private double due = paid - owed;

public CashRegister(double owed, double paid, ArrayList<Currency> currency)

{

this.owed = owed;

this.paid = paid;

this.currency = currency;

due = paid - owed;

}

public String changeDue()

{

String output = "";

for(int x = currency.size() - 1; x >= 0; x--)

{

double value = currency.get(x).getValue();

int holder = (int)(due/value);

if (holder >= 1)

{

due = due - (holder*value);

output = output + currency.get(x).getName() + ": " + holder + "\n";

}

else

output = output + currency.get(x).getName() + ": " + holder + "\n";

}

return output;

}

Essentially, the holder contains the amount of the bill/coin needed. It needs to be a whole number. I'm pretty sure that's where the error is, however it could also be the "due = due - (holder*value)." Please help as I am completely lost. If you know another way to truncate decimals or something lmk if you think that would solve the issue.

πŸ‘︎ 2
πŸ’¬︎
πŸ‘€︎ u/Ultimate_Crafter
πŸ“…︎ Sep 08 2020
🚨︎ report
On the other hand, Von Neumann stability analysis; which is related to round off error and is completely unrelated to the reasoning given for this scheme; reaches the same conclusion. This feels weird. Do I have the right to feel weird?
πŸ‘︎ 10
πŸ’¬︎
πŸ‘€︎ u/wigglytails
πŸ“…︎ Dec 16 2018
🚨︎ report
Someone explain why round off error in java happens please, I seriously don’t understand why I can not just do double == double and carry on with my day
πŸ‘︎ 3
πŸ’¬︎
πŸ‘€︎ u/j10b100
πŸ“…︎ Dec 10 2019
🚨︎ report
matlabFunction causing significant round-off error

Hi,

I’m converting a symbolic expression into a function using matlabFunction in order to evaluate it in an optimization routine. However, I noticed that if I use subs with a value I get a result which exactly matches my expected results for the function. If I evaluate the result using the same value but in the matlabFunction generated function, the result has errors in the 5th or 6th decimal place which is fairly significant. Is there a way to fix this? I tried turning off the optimize option for matlabFunction but the errors still persist.

πŸ‘︎ 10
πŸ’¬︎
πŸ‘€︎ u/supersymmetry
πŸ“…︎ Feb 13 2019
🚨︎ report
Atletico Madrid have qualified for the knockout phase of the UEFA Champions League, while Porto have qualified for the Europa League Play Off Round. uefa.com/uefachampionslea…
πŸ‘︎ 1k
πŸ’¬︎
πŸ‘€︎ u/FragMasterMat117
πŸ“…︎ Dec 07 2021
🚨︎ report
How do you anti-alias or filter data due to round-off error?

So I have some spatial R-T-Z (radius/angle/elevation) data that unfortunately has a lot of round-off on the Radius dimension.

I need to calculate the 2nd derivative off this data and thus it needs to be smoothed/filtered somehow. I currently use a typical gaussian/uniform blur but I was just wondering,

are there other kinds of techniques out there that can take care of error due to discrete binning or data roundoff?

EDIT: For reference for future searchers, I found that the Savitzky-Golay filter seems to produce great results.

https://www.mathworks.com/help/curvefit/smoothing-data.html

https://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.signal.savgol_filter.html#scipy.signal.savgol_filter

πŸ‘︎ 2
πŸ’¬︎
πŸ‘€︎ u/subheight640
πŸ“…︎ Jun 01 2018
🚨︎ report
Weight round off error

Hello, I write this post today, as I find myself in a bit of a conundrum.

While calculating the fuel and range for a flight plan (theoretical, not flying yet), I found that after rounding flight time and range, my Take Off Fuel goes from 9337,48KG to 9413,24KG.

Does anyone know what is (if there is one) the margin of error when calculating weights, fuel, and etc?

Thanks!

EDIT: Thank you all for your input!

πŸ‘︎ 2
πŸ’¬︎
πŸ‘€︎ u/ExCaliburnus
πŸ“…︎ Apr 25 2017
🚨︎ report
In January 25, 1990 during the First Gulf War, a Patriot missile defense system in Al-Dhahran, Saudi Arabia, was rendered ineffective due a Round-off error... leading to the death of 28 people. en.wikipedia.org/wiki/Rou…
πŸ‘︎ 17
πŸ’¬︎
πŸ‘€︎ u/ffualo
πŸ“…︎ Sep 27 2009
🚨︎ report
TIL The National Spelling Bee titled 8 Co-Champions after running out of words in a 3.5 Hour Final. Starting with 562 Contestants, the Final Eight continued for 20 Straight Rounds of Spelling Words without any errors. theguardian.com/sport/201…
πŸ‘︎ 23k
πŸ’¬︎
πŸ‘€︎ u/auscrisos
πŸ“…︎ Jun 26 2020
🚨︎ report
First time user of Scilab, can't get my fourier plot code to work and not sure where the problems is, keep on getting undefined variable error/round off error at line 3. any suggestions?
πŸ‘︎ 2
πŸ’¬︎
πŸ‘€︎ u/manocchiarr
πŸ“…︎ Nov 16 2017
🚨︎ report
Sig figs and Round off error

I have a question about round off error and sig figs in Lab Reports. When filling in data tables that require calculations do you leave your unrounded values in the tables for further calculations or would you round those values to the appropriate number of sig figs that match your most precise measuring device? While I understand that rounding off these values too soon will result in round off error for further calculations, it seems inappropriate to leave the unrounded values of something to 8-10 sig figs even if they aren't part of the final calculation and only values shown in your data table.

cheers

πŸ‘︎ 2
πŸ’¬︎
πŸ‘€︎ u/QuantumGains
πŸ“…︎ Oct 04 2015
🚨︎ report
Final round heavy bag after a long time off streamable.com/3v8nqh
πŸ‘︎ 56
πŸ’¬︎
πŸ‘€︎ u/KoCrazy
πŸ“…︎ Nov 25 2021
🚨︎ report
ROUND 5: Pissed Off Clown and Kid quick have been eliminated! Vote 2 more ponchy bois to be ponched
πŸ‘︎ 24
πŸ’¬︎
πŸ‘€︎ u/Notbeanburrito
πŸ“…︎ Nov 21 2021
🚨︎ report
I will some prediction tier lists for this game. I'll make another when the game releases and see how close I was. First off: Early game! (Rounds 1-15)
πŸ‘︎ 35
πŸ’¬︎
πŸ‘€︎ u/Hentree
πŸ“…︎ Nov 17 2021
🚨︎ report
CMBS Error turns off ACC

2018 Accord Touring 2.0T. Been having the well documented problem of ACC randomly turning off due to CMBS error.

I took it to dealership and told them about the TSB that is supposed to fix the issue. They said it was already installed. Test drove the vehicle and they were able to duplicate the error. They said it could be due to 2 foot driving (don’t do that), resting foot on brake (don’t do that), or due to aftermarket windshield (I don’t believe this because it works fine most of the time). Has anyone else continued to have this issue after the TSB patch was allegedly applied? I’m tempted to order Ktuner and flash the software myself, as it looks like they have integrated the patch into their tune now.

Any thoughts or recommendations? I love the vehicle but this is a big feature to have that doesn’t work half the time.

Thanks!

πŸ‘︎ 2
πŸ’¬︎
πŸ‘€︎ u/Sandersda
πŸ“…︎ Nov 11 2021
🚨︎ report
Round 2. Dropped her off today. For anyone who hasn’t been following, the paint is terrible up close. Getting that taken care of now
πŸ‘︎ 69
πŸ’¬︎
πŸ‘€︎ u/unweave
πŸ“…︎ Nov 08 2021
🚨︎ report
It’s a rounding error for them
πŸ‘︎ 8k
πŸ’¬︎
πŸ“…︎ May 21 2021
🚨︎ report
2008 9-3 2.0t. I keep getting anti-skid, anti-spin errors. Disappears if I turn the car off and on. I think it might be an abs sensor? How can I know which one and do I have to replace the entire bearing, since they are a single part? Thanks!
πŸ‘︎ 5
πŸ’¬︎
πŸ‘€︎ u/fangeld
πŸ“…︎ Nov 03 2021
🚨︎ report
Round 8! A couple of big hitters knocked out last round. I've updated the list so its easier to see which songs are left. For this round vote off 3 from each column, except Conventional Weapons and Bullets, I'm pausing those for a bit while the other albums catch up! reddit.com/gallery/qzzzoe
πŸ‘︎ 16
πŸ’¬︎
πŸ‘€︎ u/scarecr0w1886
πŸ“…︎ Nov 23 2021
🚨︎ report
ALTOIDS 10rd ammo carrier. With a little bit of trial and error and some polymer clay. This isnt a bad idea if you wanna carry some rounds in your EDC bag without it screaming "Hey look at me!, I'm a magazine."
πŸ‘︎ 1k
πŸ’¬︎
πŸ‘€︎ u/Grip_the_artist
πŸ“…︎ Mar 01 2020
🚨︎ report
My 2013 been getting the flashing green key immobilizer error (started and immediately shut off) on and off for a while , thought it was keys or immo unit error , turn out the fuse while still in tack, in horrible burned condition , replaced the fuse and good as new now. imgur.com/a/OXxgipy
πŸ‘︎ 2
πŸ’¬︎
πŸ‘€︎ u/damn_jexy
πŸ“…︎ Dec 14 2021
🚨︎ report
Noticed this flagrant error while playing NBA 2k21 the other day... This is how to instantly piss off anyone from Oklahoma, or anyone who understands the intensity of in-state rivals for that matter! Developers put a picture of Oklahoma State's campus instead of one of OU's. reddit.com/gallery/o94w6o
πŸ‘︎ 623
πŸ’¬︎
πŸ“…︎ Jun 27 2021
🚨︎ report
Video playback error -getting ripped off

Been happening a LOT today, I watch a whole video and it either says playback error at the very end, or finishes normally, but I don't get the ad reward / upgrade reduction.

Anyone else experiencing this lately? Is there a way around it? I hate watching the whole ad and getting nothing for it.

πŸ‘︎ 6
πŸ’¬︎
πŸ‘€︎ u/SoSmartish
πŸ“…︎ Nov 25 2021
🚨︎ report
Went to retrieve save data off the cloud (playing between Steam and mobile), and my exp was 1 less than what it says was saved. Possibly a rounding error? imgur.com/gallery/sRfUjvB
πŸ‘︎ 3
πŸ’¬︎
πŸ‘€︎ u/pieman83
πŸ“…︎ Apr 19 2020
🚨︎ report
[Highlight] In the final seconds of the 15 seconds of the 2019 AFC Wild Card Round, Logan Ryan picks off Tom Brady's last pass as a Patriot and returns it for a TD. youtube.com/watch?v=dB40L…
πŸ‘︎ 40
πŸ’¬︎
πŸ‘€︎ u/YiMyonSin
πŸ“…︎ Nov 22 2021
🚨︎ report
Here comes πŸ‡¦πŸ‡Ώ, flying back where it took off from and leaving a trail of shit behind it. Oh shit πŸ‡§πŸ‡· just annexed Crimea. πŸ‡ΉπŸ‡² is pregnant. πŸ‡­πŸ‡· is longer, πŸ‡·πŸ‡Έ is tiny and πŸ‡§πŸ‡¦ has a coastline. Round 9: Choose a sea to turn into land. Oh and I replaced the labels with flags and a key. It's much easier. reddit.com/gallery/r022c2
πŸ‘︎ 8
πŸ’¬︎
πŸ“…︎ Nov 23 2021
🚨︎ report
[NFL Update] Report: #Steelers GM Kevin Colbert proposed adding three more rounds to this year's NFL Draft, as it would "widen a club's margin for error" twitter.com/mysportsupdat…
πŸ‘︎ 735
πŸ’¬︎
πŸ‘€︎ u/vonheisenberg
πŸ“…︎ Apr 07 2020
🚨︎ report
TIL The ancient Greeks had known the world is round since Pythagoras, and successfully calculated the circumference of the globe when Eratosthenes measued the angles of the mid-day sun between two towns of a known distance. His calculation had only about a 10% margin of error. khanacademy.org/partner-c…
πŸ‘︎ 13k
πŸ’¬︎
πŸ‘€︎ u/DrSpoe
πŸ“…︎ Mar 11 2019
🚨︎ report
Time to (literally) dust off ol' reliable! After EVGA processed my step-up payment from a 2080S to a 3080 then emailed me saying my RMA was cancelled, and customer support failed to call me back with an answer as promised, I chalked it up to an admin error and shipped the 2080S today. Can't wait!
πŸ‘︎ 31
πŸ’¬︎
πŸ‘€︎ u/deathcovers123
πŸ“…︎ Oct 21 2021
🚨︎ report
Silver Stack Club - RAID DAY DISCOUNT - $5 off the Wall Street Silver custom round!

Wall Street Silver: Troy & The Ape (2021) - 1 Oz. Fine Silver Collectible Round

Dear fellow Silver Apes,

Silver Raid Day is here, and to celebrate this with everyone we will be reducing the price of the Wall Street Silver: Troy and the Ape round by 5.00 USDΒ per piece. Volume-based discounts will also be available for you to take advantage of as needed. This will be on top of the massive updates to pricing structure on Thursday, November 4! (See original thread here)

Interested in this round? Click here to pre-order it!

Enjoy the additional discounts on Silver Raid Day!

Sincerely,

The Silver Stack Club Team

πŸ‘︎ 64
πŸ’¬︎
πŸ‘€︎ u/NeuralBot_0
πŸ“…︎ Nov 05 2021
🚨︎ report
Issue with old coast spas hot tub - I just got back from vacation to find my hot tub with an error (see video). Temperature is about 3 degrees under target. Pumps work, but the heat circulation speed only comes on for a few seconds and turns off. Any ideas on what I can troubleshoot? v.redd.it/3r2p8g1c41u71
πŸ‘︎ 3
πŸ’¬︎
πŸ‘€︎ u/sloanvancouver
πŸ“…︎ Oct 17 2021
🚨︎ report
Tried the pattern for this little guy but for some reason it ended up looking weird, it was not round but rather pointy (considering how it's supposed to look), how do I fix this and avoid commiting the same error in mu next projects?
πŸ‘︎ 90
πŸ’¬︎
πŸ‘€︎ u/ExtraTerrestriana
πŸ“…︎ Sep 28 2020
🚨︎ report
Sami Zayn: β€œI’ll say this, @LoganPaul no doubt worked his ass off and proved a lot of people wrong, but if he never meets Sami Zayn, he never realigns his perspective, and no chance he goes 8 rounds with Floyd Mayweather. I’m glad to have played my part in this historic bout. #FloydvsLogan” twitter.com/samizayn/stat…
πŸ‘︎ 2k
πŸ’¬︎
πŸ‘€︎ u/Weezy-NJPW_Fan
πŸ“…︎ Jun 07 2021
🚨︎ report
That one TA that takes off 2 points for 5% rounding error in a homework assignment

Then he tells you that he even took off 1 point for people who had 0.22% error (yes, 0.22%)

https://preview.redd.it/si9i37s03td21.jpg?width=895&format=pjpg&auto=webp&s=68722c7f78883c31c0fd5c9b84202eacae237a08

πŸ‘︎ 12
πŸ’¬︎
πŸ‘€︎ u/-user-7
πŸ“…︎ Jan 31 2019
🚨︎ report
Anyone else getting this error when trying to view interview requests for A round?
πŸ‘︎ 28
πŸ’¬︎
πŸ‘€︎ u/fernCWM
πŸ“…︎ Nov 17 2020
🚨︎ report
I have tried to make it to round 100 so many times with 72,82, and 89 being the closest I’ve gotten before someone gets kicked. Either myself of a friend gets kicked with this Error (Baker 917 Brute Goodnight) . Any way to resolve or prevent this from happening?
πŸ‘︎ 12
πŸ’¬︎
πŸ‘€︎ u/w8ly
πŸ“…︎ Jan 31 2021
🚨︎ report

Please note that this site uses cookies to personalise content and adverts, to provide social media features, and to analyse web traffic. Click here for more information.