0

I am using OleDB Ace 12 to read an Excel (xslx) sheet containing a column with decimal values. When I open the Excel sheet on my PC a decimal value is correctly formatted as 1.850,50 (NLD culture with comma as decimal separator)

When I'm reading out the Excel sheet using OleDB (C#4.0), the string value of this field is always 1,850.50 (US format)

I've tried setting the Locale of the DataSet I fill, set the currentthread's culture and more, but the DataSet filled with OleDB adapter always returns US formatted decimals.

Can I change the way it formats the value when reading? Or is it always US format no matter what?

peter
  • 243
  • 2
  • 3
  • 9

1 Answers1

0

I think you will get it US format only. You can convert it in code:

string strFloatingNumber = "24.45"; //a floating point number in English notation
double output = 0.0; //output double number which will hold the value
double.TryParse(strFloatingNumber, out output); //convert without exception - assuming no error
MessageBox.Show(output.ToString("N2", CultureInfo.CreateSpecificCulture("nl-NL")));
Nayan
  • 3,092
  • 25
  • 34
  • Yes, but test is not 15,11. It would be 15.11 which will throw an exception when using de-DE culture to parse. – peter Oct 11 '10 at 19:34
  • I guess you did not get the hint :) Updated my answer. – Nayan Oct 12 '10 at 02:54
  • But '1,850.50' won't work. I could replace the comma, you think it's the only solution? I was hoping I could read with a specific culture, but unfortunately it seems not possible. Thanks for your help. (BTW I need Decimal, not Double) – peter Oct 12 '10 at 08:18
  • Try to analyze my answer bit more. You have the answer right here. Study bit more documentation on MSDN - that might help you in understanding how to use this answer. – Nayan Oct 12 '10 at 13:31