I'm currently using the following code to round up/down a surcharge amount (and subsequent totalPaymentAmount) if a customer pays by Credit Card.
All works fine but I've just been alerted that when there is a rollover of 5 the surcharge, and new total + surcharge are no longer correct:
customer pays 113.00
0.015 surcharge = 1.695 (which I guess should round up to 1.70 BUT IT DOESNT, IT ROUNDS DOWN TO 1.69
totalPaymentAmount = 114.70 (WHICH IS 113.00 + 1.70
, suddenly with a ROUNDED UP amount of 1.70?)
Any assistance with this would be great. Code needed please as I'm working on a live system and cant afford to try my medium level code.
I guess ideally it could work out the surcharge and add it to dOriginal
to create totalPaymentAmount
, then make surchargeAmt the difference of totalPaymentAmount - dOriginal
// work out surcharge amounts
double dOriginal = Double.parseDouble(form.getPaymentAmount());
double dSurcharge = dOriginal * 0.015;
String surchargeAmt = String.format("%.2f", dSurcharge);
String totalPaymentAmount = String.format("%.2f", dOriginal + dSurcharge);
// set new amounts