Preventing auto scientific form for numbers in python3

Viewed 11077

Is it possible to not assign a scientific/standard form number when doing calculations?

for example right now in one of the lines in my code has: number = 10**23 * 1.1

which is supposed to evaluate to 110000000000......0 or whatever, instead im assigned 1.1e+23 which is very annoying because im trying to convert IEEE754 to decimal and making specific things print out but it wont work because of the scientific notation of 1.1e+23

Ive tried looking around but no simple concise answers

2 Answers
def number(n):
    """
    如果小于1,只保留4位有效数字
    如果大于1,保留小数点后2位
    """
    if n < 1:
        n = '{:.4g}'.format(n)
    else:
        n = '{:.2f}'.format(n)

    if 'e-' in n:
        a, b = n.split('e-')
        a = a.replace('.', '')
        b = int(b)
        return '0.' + '0' * (b - 1) + a
    else:
        return n

In the above example, if it's less than 1, I keep 4 significant digits, if it's larger than 1, I keep all digits before the decimal point, and keep 2 digits after the decimal point. It's perfect for displaying price of cryptos ;)

In [61]: number(0.00000123456)                                                  
Out[61]: '0.000001235'

In [62]: number(47740.3413)                                                     
Out[62]: '47740.34'
Related