Double to String mask

  • Thread starter Thread starter John Sitka
  • Start date Start date
J

John Sitka

32.0 transformed to 000000320000000000

I guess the above would be equivalent to an numeric(18,10) datatype
the first 8 digits represent the whole part of the double
the last 10 represent the decimal part

32.50 transformed to 000000325000000000

I can see building a method (example. DoubleMask(double <adouble>) )
that returns a string after using PadLeft PadRight. Is that a good way?
 
I did it like this, citique please


private string DoubleMask(double adbl)
{
string stradbl;
char achr = '0';
adbl = adbl * 10000000000;
stradbl = Convert.ToInt64(adbl).ToString().PadLeft(18,achr);
return stradbl;
}
 
How about:

private string DoubleMask(double adbl)
{
return (adbl * 10000000000).ToString("000000000000000000");
}
 
Thanks, that's better and works smarter.

Stephany Young said:
How about:

private string DoubleMask(double adbl)
{
return (adbl * 10000000000).ToString("000000000000000000");
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top