0

I'm trying to convert a string that contains a decimal number like this.

bet1size = "0.00000001"

I've tried

betsize = int(bet1size)

but that comes up with

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: invalid literal for int() with base 10: '0.00000001'

I've also tried

betsize = float(bet1size)

but this comes up with 1e-08 and

betsize = Decimal(bet1size)

comes with with 1E-8

Why does it this happen and how can I do it properly?

2
  • what do you want as output? 0.00000001 is the same as 1e-08 aka 10^-8 Commented Jun 30, 2014 at 9:36
  • I want to convert it to a number so I can double it then I was going to convert it back to a string, but like this the string ends up being 2e-08 not 0.00000002 Commented Jun 30, 2014 at 9:40

3 Answers 3

2

The scientific notation is just a convenient way of storing/printing a floating point number. When there are a lot of leading zeros as in your example, the scientific notation might be easier to read.

In order to print a specific number of digits after a decimal point, you can specify a format string with print:

format(float(bet1size), '.8f')
Sign up to request clarification or add additional context in comments.

Comments

0

It's being done "properly" by float(). 1e-08 is "0.00000001".

It's just a matter of how you format it for printing, the number is the same.

Comments

0

int means integer. You can't store a decimal number in a int. For the two other, it means 1 * 10^-8, which equals to 0.00000001.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.