Reputation: 645
I have columns of parsed hex values from an Excel file
4.0
123.0
FFE
5432535.0
and the list goes on. I'm writing all the data in this formatted C header file and do NOT want any of the data to the right of the decimal or the decimal itself.
For example:
4.0 -> 4
5432535.0 -> 5432535
What's the best way to go about doing this?
My problem is they are hex val ,so they can contain letters as well. The data is being parsed using XLRD and stored in the variable in this type of format.
cell_val3 = sheet.cell_value(row_iteration, 20)
Upvotes: 0
Views: 85
Reputation: 16711
Just reassign the string to the first element after splitting by periods: s = s.split('.')[0]
Upvotes: 2
Reputation: 1564
Say this is stored in the variable number
. I would do
number = str(number)
number = number[:number.index('.')]
number = int(number)
This performs a slice of the variable starting from the first position and ending on the character it finds before the '.'; you may have to make the input a String first, depending on how you're reading the data in.
Upvotes: 0