Reputation: 9
When I load xlsx file. I have a number IBAN with scientific notation. For example:
7.810500161524e+25
This number should be:
78105001615240000000000000
I want to convert this number to string, but I get result:
'7.810500161524e+25'
I thought if I converted to int and then to string it would be the correct result, but again I get wrong result:
'78105001615239996483043328'
Anyone have any idea?
Upvotes: -1
Views: 1254
Reputation: 104712
You can convert your string '7.810500161524e+25'
to a decimal.Decimal
number without altering its precision at all the way you will if you convert it to a floating point value. Then (if necessary) you can convert the decimal value to an integer or a string.
import decimal
scientific_notation = '7.810500161524e+25'
decimal_number = decimal.Decimal(scientific_notation) # Decimal('7.810500161524E+25')
int_number = int(decimal_number) # 78105001615240000000000000
fixed_point_string = format(decimal_number, 'f') # '78105001615240000000000000'
Upvotes: 1