1. No Profile Picture
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
Aug 2013
Posts
232
Rep Power
5

#### Question about Determining TaxCents as a remainder

Hello,

So after spending some time with this exercise, I have managed to get the right amount of money that should be taxed on an individual based on their income, but the issue I have is how to find the remainder cents as if the entire tax amount was a decimal value (double).

Anyway, here's my code, I think I might have it, but its the 0.5 that's bugging me and I think it might be eliminated with the use of the mod operator, but I'm no sure:

Code:
```/* 3. Write a program that defines a floating-point variable
* initialized with a dollar value for your income and a
* second floating-point variable initialized with a value
* corresponding to a tax rate of 35 percent. Calculate
* and output the amount of tax you must pay with the dollars and cents
* stored as separate integer values (use two variables of type int
* to hold the tax, perhaps taxDollars and taxCents).
*/
public class Chapter2_Exercise3 {

public static void main(String[] args){

float current_income = 655550;

// 45550

float tax_rate = (float)(0.35);

int taxDollars = (int)(current_income * tax_rate);

// This part will calculate the remainder that contains cents:

double taxCents = (double)(current_income * tax_rate);

System.out.println("\nHere is your current income: \$" + current_income);

System.out.println("\nHere is the value of tax_rate: " + tax_rate + "%");

System.out.println("\nHere is the tax you have to pay on your income: \$" + taxDollars);

System.out.println("\nHere is the amount of tax cents that are remaining: " + taxCents);

}

}```
2. how to find the remainder cents as if the entire tax amount was a decimal value (double).
Is this your question: given a tax amount of 12.34, how to extract the 34?
One way: (12.34 - 12)*100
3. No Profile Picture
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
Aug 2013
Posts
232
Rep Power
5
(12.34 - 12) * 100

Exactly. That was the problem I was having just to extract the .34 for the cents remaining, only to actually do so with the variables I used.

Its Damn easy to do before hand, but using variables in this case was just a little different.

I was guessing to somehow use the mod operator to get the remainder, so awesome for leading me on the right track.