问题
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?
回答1:
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")));
来源:https://stackoverflow.com/questions/3909216/oledb-read-excel-decimal-value