开发者

OleDB Read Excel decimal value

开发者 https://www.devze.com 2023-01-20 01:23 出处:网络
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 m开发者_JS百科y PC a decimal value is correctly formatted as 1.850,50 (NLD

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 m开发者_JS百科y 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?


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")));
0

精彩评论

暂无评论...
验证码 换一张
取 消