473,412 Members | 2,075 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 software developers and data experts.

Baseball Percentages -- No Zero

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.)
Apr 21 '07 #1
4 1786
Atli
5,058 Expert 4TB
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.
Apr 21 '07 #2
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?


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.
Apr 21 '07 #3
Savage
1,764 Expert 1GB
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
Apr 21 '07 #4
Thanks. I'll try that.

Use substring.

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

Savage
Apr 21 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: michael | last post by:
I've got a 3-column layout using percentages to define width of each div-column. #left-col { width: 20%; background-color: green; float:left; } #center-col { width: 60%; background-color: blue;...
1
by: Megan | last post by:
quick summary: i'm having problems trying to group fields in a report in order to calculate percentages. to calculate percentages, i'm comparing the results from my grouped fields to the totals....
26
by: Mike Barnard | last post by:
Hi all. I am playing with html and css. I don't (yet) have a working site, I'm just trying to build a working, basic template I can use for a couple of ideas I have. I recall reading a...
5
by: Chris H | last post by:
I am wanting to write a function for a poker league manager that will detrmine players finishing points in a tournament depending on the amount of players that played... In other words when the...
9
by: ankitdesai | last post by:
I would like to parse a couple of tables within an individual player's SHTML page. For example, I would like to get the "Actual Pitching Statistics" and the "Translated Pitching Statistics"...
1
by: Bob Alston | last post by:
I need to produce a report like this Color: # % ------ --- --- White 10 20 Black 25 50 other 15 30 ---- ---- Total 50 100
4
by: sqlservernewbie | last post by:
Hello, I'm trying to something that just works in Oracle, but does not in Sql Server. How can I get the percentage of two counts to be returned on each row of the query? select count(sid),...
9
by: AZKing | last post by:
Hi all, I would like to know how do you go about calculating percentages in Access. For example, in a form I have 3 combo boxes with drop down menus where a user can select "Yes" or "No" and a...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.