Ich habe in Python verschiedene Probleme mit Rundungsfehlern:
Beispiel1: in den Meisten Fällen ist s!=s1, wieso?
Code: Alles auswählen
s=-2
s1=-2
searchend=2.2
while s < searchend:
print s,s1
s=s+0.2
s1=round(s1+0.2,1)
print s==s1
In einer Excel Tabelle habe ich folgende 2 Werte:
X=[0.031916156411171, 0.169034600257874], das unten angegeben Programm liest aber folgendes:
X=[0.031933994107021135, 0.16905243795372371], was kann ich dagegen tun
Code: Alles auswählen
import clr
clr.AddReference("Microsoft.Office.Interop.Excel")
#import winforms
clr.AddReferenceByPartialName("System.Windows.Forms")
clr.AddReferenceByPartialName("System.Drawing")
from System.Windows.Forms import *
import Microsoft.Office.Interop.Excel as Excel
class Workbook:
def __init__(self):
openFile = OpenFileDialog()
openFile.Filter = "xls files (*.xls)|*.xls"
if openFile.ShowDialog() == DialogResult.OK:
filename = openFile.FileName
print 'Loading data from ', filename, '...'
self.excel = Excel.ApplicationClass()
self.excel.Visible = True # makes the Excel application visible to the user
self.workbook = self.excel.Workbooks.Open(filename)
def ReadCell(self,sheetname,line,col):
self.worksheet = self.workbook.Worksheets(sheetname)
cell = self.worksheet.Cells(line,col)
return cell.Value2