Commit 1674051e authored by Recolic Keghart's avatar Recolic Keghart 🎱

bug fix: fucking python num conv error

parent 282f2433
import xlrd
import csv, io
def float_to_str(f):
float_string = repr(f)
if 'e' in float_string: # detect scientific notation
digits, exp = float_string.split('e')
digits = digits.replace('.', '').replace('-', '')
exp = int(exp)
zero_padding = '0' * (abs(int(exp)) - 1) # minus 1 for decimal point in the sci notation
sign = '-' if f < 0 else ''
if exp > 0:
float_string = '{}{}{}.0'.format(sign, digits, zero_padding)
else:
float_string = '{}0.{}{}'.format(sign, zero_padding, digits)
return float_string
def xlsx2csv(xlsxPath, sheetIndex, outputFd):
wb = xlrd.open_workbook(xlsxPath)
sh = wb.sheet_by_index(sheetIndex)
......@@ -8,7 +22,7 @@ def xlsx2csv(xlsxPath, sheetIndex, outputFd):
def fuck_number_ele(ele):
if type(ele) is float:
s = str(ele)
s = float_to_str(ele)
if 'e' in s.lower():
raise RuntimeError('Fuck python Float2Str: THIS IS A BUG. PLEASE REPORT.')
if s.endswith('.0'):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment