// rounding with double to store currency in dollars
double rate = 0.05; // 5%
double amount = amountInDollars;
// calculate the tax
double tax =  amount * rate;
// round by converting to pennies, rounding then converting back to dollars.
double tax = Math.rint(tax * 100.) / 100.;

// rounding with long to store currency in pennies.
double rate = 50; // 5% = 50/1000
long amount = amountInPennies;
// calculate the tax rounded to the nearest penny.
long tax = (amount * rate + (1000/2)) / 1000;