San9096
San9096

Reputation: 251

Converting a decimal number from str to float

I have the following number of type float:

1.019e-05

To convert it to a decimal number, i did this:

print("%.10f" % float(1.019e-05))

Which gives the following output: 0.0000101900

The problem is that 0.0000101900 is of type str, but i need to make some calculations with that number. How can i convert 0.0000101900 from string to a number again? if i use float()the decimal will be converted again to an exponential. Am i forced to use the exponential number here?

Upvotes: 0

Views: 136

Answers (1)

awarrier99
awarrier99

Reputation: 3855

The number is a float and has the same value no matter how it looks - the scientific notation used is just a way of representing how the data looks in a more concise way. By doing your formatting string, you are formatting the number to look a certain way for output, but that creates a string representation of the number rather than "converting it to a decimal number". You can't change the way Python natively represents a float, but I'm not understanding why this matters to you because it doesn't change the actual value of the number, just how it looks when printed out

Upvotes: 2

Related Questions