简体   繁体   English

将科学记数法转换为字符串

[英]Convert Scientific Notation to String

When I load xlsx file.当我加载 xlsx 文件时。 I have a number IBAN with scientific notation.我有一个带有科学计数法的数字 IBAN。 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:我想如果我转换为 int 然后再转换为 string 这将是正确的结果,但我再次得到错误的结果:

'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.您可以将字符串'7.810500161524e+25'转换为decimal.Decimal数。如果将其转换为浮点值,则不会完全改变其精度。 Then (if necessary) you can convert the decimal value to an integer or a string.然后(如有必要)您可以将十进制值转换为 integer 或字符串。

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'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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