# Casting from a whole number to a percent

• September 22nd, 2013, 04:15 PM
///M Dood
Casting from a whole number to a percent
Hi,

I had a question about data type casting. Is it possible to take an integer of say 25, and convert that into being a percent so 0.25? How would that look? Where could i go to kind of grasp how to do it?
• September 22nd, 2013, 04:50 PM
GregBrannon
Re: Casting from a whole number to a percent
Casting from one data type to another is not the same as dividing an integer by 100.0 and obtaining a double result. This could be an interesting and simple program to demonstrate both casting and the use of various data types in the equation to determine what must be done with it or to it to obtain the desired results.
• September 22nd, 2013, 05:15 PM
///M Dood
Re: Casting from a whole number to a percent
Wow, i just got that first try. Thank you! Code below for reference. You da man Greg

Code :

```class Retirement { public static void main(String[] args) { int age = 30; double salary = 30000.0; int limit = 0; String sp = " ";   System.out.println("---------------------------------------------------------------------------"); System.out.println("Age Salary (\$) Limit (%) Contri. (\$) Cumul. Contribution (\$)"); System.out.println("---------------------------------------------------------------------------");   do { if (age > 50) { limit = 40; } else if (age >40 && age <= 50) { limit = 30; } else { limit = 25; } if (age > 30) { salary = (salary + (salary * 0.03)); } int contribution = (int)((salary / 100) * (int)limit); if (age % 5 == 0) { System.out.println(age + sp + (int) salary + sp + limit + sp + contribution ); } age++; } while (age <= 60); } }```

--- Update ---

It won't let me edit my post, but int contribution is what i was trying to do.