How do I format a double
I have:
double somevar = 3.45;
I need to format it to have the following results:
- "
000345
" - The length should be only 6 - "
3.45____
" - The length should be 8, left-alignment, the other part should be filled by blanks. (I use underlines instead blanks开发者_如何转开发 here because of some bug on this service that doesn't allow showing this string properly, but it actually doesn't matter, because fillers should be defined in the format string.)
It's so easy to do just by programming but I need to achieve it only using format string. Is it possible?
That's:
string format="???";
float number = 3.45;
string output = string.Format(format, number);
Actually only the first problem is left without answer.
Thanks! I like you style guys, you don't like this question because you cannot answer it, right?
double somevar = 3.45;
string s = string.Format("{0:000000}", (int)(somevar*100.0));
string t = string.Format("'{0,-8:0.00}'", somevar);
Took about 30 seconds to look at the docs on string.format.
精彩评论