格式化十进制前的2位数字和十进制后的2位数字,Excel Interop

我想从Excel电子表格中的单元格中读取数值

10.50

20.25

41.10

我正在使用Excel Interop来检索值。

下面的工作值小于10,但是当10或更大的值被设置为0.我怎样才能正确格式化使用NumberFormat行动?

double doubleHours = 0.0; if (Extension.IsNumeric(excelWorksheet.Cells[rowCount, columnCount].Text)) { Excel.Range range = excelWorksheet.Cells[rowCount, columnCount]; range.EntireColumn.NumberFormat = "#,##0.00"; double.TryParse(excelWorksheet.Cells[rowCount, columnCount].Text, out doubleHours); //continue processing } 

 double doubleHours = 0.0; Excel.Range range = excelWorksheet.Cells[rowCount, columnCount]; string value = range.Value2.ToString(); if (double.TryParse(value, out doubleHours)) { //continue processing }