Search code examples
pythonseleniumselenium-webdriverfloating-pointexecute-script

Selenium execute_script sending float number in scientific notation


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?


Solution

  • Can be done like this:

    a = 0.00001
    
    b = "{:.10f}".format(a).rstrip('0')