Click here to Skip to main content
15,886,788 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everyone,

I am writing a small app that calculates the correct number of Red Blood Cells per Litre of whole blood.

It is based on enterinf the counts seen in 5 squares through a microscope, and then running this total through some math routines.

here is an example.

1) Count and enter the cells as seen through the microscope, this totals (as an example) 2500

2) Multiply this by the dilution factor of 200

3) Multyply by 10,000 (This is the factor used to get cells per ml of blood)

4) Multyply this by 1000 to get a total cell count per litre.

Using the above, and using a double my application correctly produces the following number of cells per litre

5000000000000


I now want my application to correctly show the science version below

5.00 X 10^12 /L

so, first of all I want to format the number to 2 decimal places, so we would have 5.00 or 3.45 or 6.88 etc etc,

and, secondly, I want to be able to display X 10^12 as the power, however, if the cell count was very low, it may be as an example

1.74 X 10^10 and not 5.00 X 10^12 (ie the 10th power and not the 12th power)

So how would I format the number to 2 decimal places, rounding it up AND display the correct science notation or power?

Thank you VERY much for advice, I am still learning.

p.s. I am outputting the value, e.g 5.25 in a colum on a list box, and the power, e.g. X 10^12 in the next colum on the list box.

Kind Regards,
Steve
Posted
Comments
BobJanova 14-Jul-11 6:51am    
Will 'G3' not get close enough? As GenJerDan mentions you can then use String.Replace to change E to ×10^ if you want, but as you can't do the superscript, that isn't much better.

Take a look at string formatting routines, either on MSDN or here.[^]
 
Share this answer
 
Hi,
Just to add,

I cant seem to find anything there that shows how to show the power after the number.

e.g 5.25 X 10^12

Thank you

Steve
 
Share this answer
 
Comments
GenJerDan 13-Jul-11 16:49pm    
You just need to parse and replace some characters. For instance, if it returns 5.25E+12 do a .Replace("E+"," x 10^") on the string, which should reformat it to "5.25 x 10^12"

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900