Connecting Tech Pros Worldwide Forums | Help | Site Map

Baseball Percentages -- No Zero

Newbie
 
Join Date: Mar 2007
Posts: 10
#1: Apr 21 '07
My program is dividing the number of hits by the number of "at bats," and I'm multiplying it by 1.0 so that it ends up as a double.

But it always gives me the first "zero" (as in "0.427"), whereas a baseball percentages doesn't include that first digit.

Casting it as a float gives me the same result.

I'm sure this is easy, but how do I get rid of that first zero? (I'm already "setprecision"-ing it to (3) to get the right percentage.)

Atli's Avatar
Moderator
 
Join Date: Nov 2006
Location: Iceland
Posts: 3,748
#2: Apr 21 '07

re: Baseball Percentages -- No Zero


Well... whether basball statistics show it or not, the zero is still there. Any numeric type in any programming language is aware of this fact and no baseball fan will ever convince them otherwise.

The question is, what are you using these numbers for?
If you are storing them your gona want to keep them as doubles or floats so you can use them as numbers later on.
If you are just displaying them, however, you could convert them into strings and simply remove the first char and you'd be wrid of that zero.
Newbie
 
Join Date: Mar 2007
Posts: 10
#3: Apr 21 '07

re: Baseball Percentages -- No Zero


I'm calculating them, adjusting them after I get new information, and then displaying them after that.

If I convert it to "string," how would I "remove the first character?" Would it be something like:

Expand|Select|Wrap|Line Numbers
  1.  cout << string[2] << string[3] << string[4]; 
thereby displaying only the appropriate (last three) digits?
Am I misunderstanding something?


Quote:

Originally Posted by Atli

Well... whether basball statistics show it or not, the zero is still there. Any numeric type in any programming language is aware of this fact and no baseball fan will ever convince them otherwise.

The question is, what are you using these numbers for?
If you are storing them your gona want to keep them as doubles or floats so you can use them as numbers later on.
If you are just displaying them, however, you could convert them into strings and simply remove the first char and you'd be wrid of that zero.

Savage's Avatar
Expert
 
Join Date: Feb 2007
Posts: 1,737
#4: Apr 21 '07

re: Baseball Percentages -- No Zero


Quote:

Originally Posted by jsta43catrocks

I'm calculating them, adjusting them after I get new information, and then displaying them after that.

If I convert it to "string," how would I "remove the first character?" Would it be something like:

Expand|Select|Wrap|Line Numbers
  1.  cout << string[2] << string[3] << string[4]; 
thereby displaying only the appropriate (last three) digits?
Am I misunderstanding something?

Use substring.

If u don't know how to use it check this

Savage
Newbie
 
Join Date: Mar 2007
Posts: 10
#5: Apr 21 '07

re: Baseball Percentages -- No Zero


Thanks. I'll try that.

Quote:

Originally Posted by Savage

Use substring.

If u don't know how to use it check this

Savage

Reply