Win a copy of The Java Performance Companion this week in the Performance forum!

# Printf and Equations

Elle de Vasquez
Greenhorn
Posts: 6

------------------------------------------------
Supreme Commander: Forged Alliance

Information SylverMoon74 GreenChaos86
------------------------------------------------

Games Played 20 20
Games Won 7 13
Avg. Games Won , 0.35 0.65
------------------------------------------------

Q1 - Avg. Games Won - has a comma (,) after it...why?
Q2 - I want to use the equation for avgw1 and avgw2 (the part that's commented out), but it gives me 0.00 as answers for both columns. Did I do the math wrong? the formatting?

Help!

Thanks much!
Sylver

Sheriff
Posts: 14691
16
Q1 : Because you're printing one ! Look closely.

Elle de Vasquez
Greenhorn
Posts: 6
Oh good god...I just saw it now that you've pointed it out >.< Thanks!

Anything for q2?

Sheriff
Posts: 14691
16
Q2 : you'll have to make one of the two operands a double, otherwise the result will be an int (check this link). Try to cast one of the operands.

Elle de Vasquez
Greenhorn
Posts: 6
Oh! Got it, thank you VERY much!!! <3

------------------------------------------------
Supreme Commander: Forged Alliance

Information SylverMoon74 GreenChaos86
------------------------------------------------

Games Played 20 20
Games Won 7 13
Avg. Games Won 0.35 0.65
------------------------------------------------
Got it to work making games won a double instead of just an int

fred rosenberger
lowercase baba
Bartender
Posts: 12146
30
In my opinion, it should be an int. You can't win part of a game (unless you count a tie as a half), so logically it makes sense for it to be an int.

What I would do is cast it during the computation:

double avgw1 = (float) gw1/gp1;
double avgw2 = (float) gw2/gp2;