-1

I have a string and i want to convert it to float. When i convert my string to float it returns me something different. My code is;

a="0.0000010232"
print(float(a))

What i expect: 0.0000010232
What i get:    1.0232e-06

So what do i need to do?

  • A floating point number has a value, not a presentation. `.2`, `0.2`, `2.0E-1`, and `.0002e3` are four different ways to display the same value. If you need to retain both the value *and* the presentation of a number, you'll need to keep both a string and the number. That's not very convenient or efficient, but it's also very rarely needed. You can choose the presentation of a floating point number. Contrast `print("{:.11f}".format(0.0000010232))` with `print("{:.4e}".format(0.0000010232))`. Then read https://docs.python.org/2.7/library/string.html#format-string-syntax. – rici May 15 '21 at 05:32

1 Answers1

1

use format

print format(0.00001357, 'f')

Output:

0.00001357

anirudh
  • 1,436
  • 5
  • 18