0

I have this code where I use execute_script to modify the of an element, I need to set it to a float number, I used this code:

WebDriverWait(driver, timeout).until(EC.element_to_be_clickable((By.ID, 'dice_bet')))
driver.execute_script(f"document.getElementById('dice_bet').innerHTML = '{bet}';")

It does actually send the float number, but using scientific notation, I'm sending 0.0001, and it shows up as 1e-4, how can I make it actually send the float 0.0001?

Javier Jerez
  • 360
  • 4
  • 16
  • 0.0001 and 1eāˆ’4 are the same number. If you want to show a particular string of characters, not a number, use `.toFixed` or `.toPrecision` to convert it to a string. In JavaScript with a variable named `bet`, that would be something like `bet.toFixed(4)` or `bet.ToPrecision(7)`, but you have some other layer of software in there, so I do not know if it would be `...innerHTML = '{bet}'.toFixed(4);` or `...innerHTML = '{bet}.toFixed(4)';` or `...innerHTML = {bet}.toFixed(4);` or what. – Eric Postpischil Jan 12 '22 at 12:52

1 Answers1

0

Can be done like this:

a = 0.00001

b = "{:.10f}".format(a).rstrip('0')
Javier Jerez
  • 360
  • 4
  • 16