why not support .ToString("##0.00")

  • Thread starter Thread starter neeme
  • Start date Start date
N

neeme

everyone:

double d = 1.23;

string s = d.toString("##0.00");


s is "1.23" !

why not is " 1.23" ?


Thank you!
 
Neeme:

Change it to this...
double d = 1.23;
string s = d.ToString("#00.00");
MessageBox.Show(s);
 
If your problem is, that you like the doubles to be right-aligned, then i
have to say you, that you will never get this with such Format-String!

Because a Blank (" ") will consume much less space then a number ("0" for
example has more width than "1" has more than " ")

i you like to right-align the number, you should look, if the control
support that (ListView-columns for example have a property for that) or try
to draw it by yourself....

if you just need some spaces before the numbers you can write a litte
function the will do something like that (pseudo-code):

return = RightString(" "+double.ToString(##0.00), 6);

I don't know what you like to do so it's hard to give the right tip


Boris
 
I do it OK!


double d = 3.14;

string str = d.ToString();

str = LeftSpace(str,6);


public static string LeftSpace(string sv,int c)
{
if(sv.Length >= c)
{
return sv;
}
int af = c - sv.Length;
for(int i=0;i<af;i++)
{
sv = " "+sv;
}
return sv;
}
 
Back
Top