Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

formatting decimals

Status
Not open for further replies.

gib99

Programmer
Mar 23, 2012
51
CA
Hello,

I'm trying to wrap my head around formatting decimals.

I have a specification that needs to be met, and it's outlined as follows:

For decimals between +/-0.0000001 and +/-100000: Optional ‘-‘ character, followed by 5 significant digits before the decimal, a ‘.’ character, followed by 6 significant digits after the decimal. If less than 5 significant digits before the decimal, pad with spaces; the optional ‘-‘ character will be right justified. If less than 6 significant digits after the decimal, pad with zeros.

For decimals below -100000 or above 100000: Optional ‘-‘ character, followed by “0.” and 6 significant digits, followed by ‘E’, followed by ‘-‘ or ‘+’, followed by a 2 digit exponent. If the value has less than 6 significant digits, pad with zeros. If the exponent has less than 2 significant digits, pad with zeros.

For 0.0m: "_____0.000000" (<-- where _ means space)

I've read the following MSDN articles:


...and they've helped me wrap my head around some rather simple cases, but the one above is quite complex and I'm getting very confused (especially with the whitespace padding--is that even possible?). Can anyone help me construct a format string that will meet the above specifications?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top