How to get the fraction and exponent of a real number in Python

1 Answer

0 votes
import math

d = 3.14

# Mantissa is the fractional part of a number = 0.785000
fraction, exponent = math.frexp(d)

print(f"fraction = {fraction:.3f} exponent = {exponent}")



'''
run

fraction = 0.785 exponent = 2

'''

 



answered Jun 30, 2025 by avibootz
...