0

I have this number:

value='0.00000036'

as string I want to calculate how much is value*2 or value+value (0.00000072) and apparently it is not an easy task. I tried to use :

decimal.Decimal(value)

and it gets me with :

Decimal('3.6E-7')

Everything works fine when i'm using higher number (0.0000036) but it's useless to me.

martineau
  • 119,623
  • 25
  • 170
  • 301
user2396640
  • 359
  • 4
  • 24
  • 4
    Okay, and what's wrong with the `Decimal('3.6E-7')` result? – Karl Knechtel Dec 06 '20 at 19:53
  • Does this answer your question? [Convert float to string in positional format (without scientific notation and false precision)](https://stackoverflow.com/questions/38847690/convert-float-to-string-in-positional-format-without-scientific-notation-and-fa) – fdermishin Dec 06 '20 at 19:56
  • @KarlKnechtel I want to see : 0.00000072 – user2396640 Dec 07 '20 at 07:49
  • @fdermishin It doesn't. I already have a string, I want to convert it to number, multiply, add and subtract and then display it. – user2396640 Dec 07 '20 at 07:50
  • 2
    So what is the problem? 3.6E-7 is the same as 0.00000036. Everything works as expected – fdermishin Dec 07 '20 at 08:29

3 Answers3

2
value='0.00000036'
decimal_value = decimal.Decimal(value)
print(format(decimal_value, 'f'))
0.00000036

If you want to multiply it by 2, just do it like so:

value='0.00000036'
decimal_value = decimal.Decimal(value) * 2
print(format(decimal_value, 'f'))
0.00000072
fdermishin
  • 3,519
  • 3
  • 24
  • 45
0

Just do this it will solve you problem of suppressing scientific notation.

import numpy as np
import decimal
value='0.00000036'
np.format_float_positional(decimal.Decimal(value), trim='-')

Output:'0.00000036'

Sachin Rajput
  • 238
  • 7
  • 26
0

Try to use f strings.

import decimal
value='0.00000036'
decimal_value = decimal.Decimal(value) * 2 # change * to + - / etc..
print(f'{decimal_value:f}') # means convert to float

Output:

0.00000072
Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
ppwater
  • 2,315
  • 4
  • 15
  • 29