decimal places

  • Thread starter Thread starter Next
  • Start date Start date
N

Next

hello

I am trying to format numbers coming from a datareader using the code below.
But it is not working.
How do I format decimal places? Thanks in advance!

NumberFormatInfo numFormat = new NumberFormatInfo();

numFormat.NumberDecimalDigits = numFormat.CurrencyDecimalDigits =
Convert.ToInt16(dr["decimal_places"]);


Double myDouble = Double.Parse(dr["number"].ToString(),numFormat);
 
Try the following:

int decimal_places = Convert.ToInt32(dr["decimal_places"]);
string formatVal = "00.";
formatVal = formatVal.PadRight(decimal_places, '0');
double val = Convert.ToDouble(dr["number1"].ToString(formatVal));

Kind of an odd way to do it -- even I think so :) -- but it looks like it would work to me. Maybe by looking at my rambling above it gave you better way of doing it.

Alan Washington
http://www.aewnet.com

hello

I am trying to format numbers coming from a datareader using the code below.
But it is not working.
How do I format decimal places? Thanks in advance!

NumberFormatInfo numFormat = new NumberFormatInfo();

numFormat.NumberDecimalDigits = numFormat.CurrencyDecimalDigits =
Convert.ToInt16(dr["decimal_places"]);


Double myDouble = Double.Parse(dr["number"].ToString(),numFormat);

User submitted from AEWNET (http://www.aewnet.com/)
 
Back
Top