We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,078 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?

# Convert integer to double for output of data

I need my overall data to all be output as double, but my counter is an int, and i imagine you cant use a double as a counter, so when it goes to compute my data, theres a mismatch between my counter and the rest . i need a way of converting my data to double for out put. Here's my code....i have a test also, all it does is call the main method.

``````public class Salary
{

public void calcSalary()
{

int wages[]={50000,40000,30000,20000,10000,60000,35000,46000,23000,19000};

final int TOTAL_LENGTH=10; //declare constant
int total[]=new int[TOTAL_LENGTH];
int bonus;
int counter;

System.out.printf("\n%s\t%11s\n\n","REP","SALARY");

for (counter=0; counter <total.length; counter++)

System.out.printf("%2d\t%10d\n",counter, wages[counter]);

counter=0;

System.out.printf("\n\n\n%s\t%10s\n\n","BONUS","TOTAL"); //column headings

while (counter<total.length)
{

if (wages[counter]<=19000)
{

bonus=wages[counter]/100*30;
total[counter]=wages[counter]+bonus;
System.out.printf("%d\t%10d\n",bonus,total[counter]);

}

if (wages[counter]>19000 && wages[counter]<=40000)
{

bonus=wages[counter]/100*20;
total[counter]=wages[counter]+bonus;
System.out.printf("%d\t%10d\n",bonus,total[counter]);

}

if (wages[counter]>40000)
{

bonus=wages[counter]/100*10;
total[counter]=wages[counter]+bonus;
System.out.printf("%d\t%10d\n",bonus,total[counter]);

}

counter=counter+1;

}

}

}
``````
3
Contributors
3
Replies
44 Minutes
Discussion Span
1 Year Ago
Last Updated
4
Views
Question
Answered
MichaelCJ10
Newbie Poster
24 posts since Feb 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

well, why wouldn't you be able to use a double as a counter?
and converting an int to a double? what good whould that do? you would have decimals, yet, but since every value stored in an int is always rounded (since it has no decimal capacity) all your prints will end with .00, so what use would that be?

stultuske
Industrious Poster
4,375 posts since Jan 2007
Reputation Points: 1,318
Solved Threads: 610
Skill Endorsements: 24
zeroliken
Nearly a Posting Virtuoso
1,346 posts since Nov 2011
Reputation Points: 214
Solved Threads: 205
Skill Endorsements: 14

yah, noticed after I made my post.

stultuske
Industrious Poster
4,375 posts since Jan 2007
Reputation Points: 1,318
Solved Threads: 610
Skill Endorsements: 24
Question Answered as of 1 Year Ago by stultuske and zeroliken

# This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help

You
View similar articles that have also been tagged:

© 2013 DaniWeb® LLC
Page rendered in 0.0705 seconds using 2.79MB