简体   繁体   中英

Convert Scientific Notation to String

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?

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'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM