2

I am trying to show decimal values instead of exponential values as it is required for end user. You can see the code below,

currentValue1='1.56e-65'
print("%f" % float(currentValue1))
print(float(currentValue1))

output is:
0.000000
1.56e-65

I want to know, is there any way to show float value with all decimal values dynamically without formatting? something like following

print("%.65f"%currentValue)

vindev
  • 2,240
  • 2
  • 13
  • 20
VNS
  • 158
  • 1
  • 10
  • What does "all decimal values" mean? Floats are stored in binary (with 53 bits for the significant digits), and once you convert the string representation to a float the original decimal form of the number is lost. And of course if you convert a float back to a decimal string the trailing digits will be different due to errors incurred in the conversion processes. – PM 2Ring Jan 25 '18 at 10:18
  • Possible duplicate of [Formatting floats in Python without superfluous zeros](https://stackoverflow.com/questions/2440692/formatting-floats-in-python-without-superfluous-zeros) – Aran-Fey Jan 25 '18 at 11:46
  • The whole point of formatting is that it allows you to control the float representation. Use formatting; that's exactly what it's for. – Mark Dickinson Jan 25 '18 at 12:15
  • 1
    BTW, I'm skeptical that the end user _really_ wants to see `0.0000000000000000000000000000000000000000000000000000000000000000156` in this case. Are you sure that's what you want? – Mark Dickinson Jan 25 '18 at 12:52
  • @MarkDickinson yes, i am sure. But it is not about user front, but it is about UI front. In the JSON response, they want to see all decimal values. But anyway thanks for your responses. – VNS Jan 29 '18 at 11:54
  • All, thanks for your responses, there is no way i am really found to do this, so i made this conversion from UI side by accepting exponential values. Thanks for all your quick support – VNS Jan 29 '18 at 11:55

0 Answers0