I thing split() function do not work correctly if I want split number as string which one I converted from float.
Main question is how to fix my code.?
To show you my problem I wrote short script in python. You can copy and run.
#!/usr/bin/env python3
# coding=utf-8
def f_test(number):
print(f"I will split {number}")
if isinstance(number, float):
print('This number is float')
number = str(number)
print(f'I changed type to str: {type(number)}')
else:
print('This number is string')
l1 = number.split('.')
print(l1)
print()
f_test(2.12)
f_test('2.12')
f_test(0.1)
f_test('0.1')
f_test(0.000000001)
f_test('0.000000001')
f_test(0.000107)
f_test('0.000107')
f_test(0.0000107)
f_test('0.0000107')
Because i do not know the type of this number, I have to check is that float or string. If is float I convert it to str.
In my opinion is something wrong with conversion float to string, because after conversion python show type as string, but print show the following form significand *(base)^exponent for float
For test i used numbers as float and str. That what i got you can see bellow.
Strange behavior for 0.000000001 and 0.0000107.
Generally split doesn't work correctly for all numbers as float converted to string In situation when after conversion print show float representation like this 1.07e-5
I will split 2.12
This number is float
I changed type to str: <class 'str'>
['2', '12']
I will split 2.12
This number is string
['2', '12']
I will split 0.1
This number is float
I changed type to str: <class 'str'>
['0', '1']
I will split 0.1
This number is string
['0', '1']
I will split 1e-09
This number is float
I changed type to str: <class 'str'>
['1e-09']
I will split 0.000000001
This number is string
['0', '000000001']
I will split 0.000107
This number is float
I changed type to str: <class 'str'>
['0', '000107']
I will split 0.000107
This number is string
['0', '000107']
I will split 1.07e-05
This number is float
I changed type to str: <class 'str'>
['1', '07e-05']
I will split 0.0000107
This number is string
['0', '0000107']
I am using Python 3.8.6