0

I'm trying to change a value, which is parsed through CGI over GET to Python before I want to send all the values over MQTT with JSON.

The value is as follows:

exposure = "0.0"

which is gained over CGI like so:

if form.getvalue("exposure"):
        req["excompensaton"] = form.getvalue("exposure")

Sadly, however, the value needs to be "0", not "0.0" before I can send it over MQTT with JSON.

I've tried:

if form.getvalue("exposure"):
        req["excompensaton"] = int(form.getvalue("exposure")

Sadly this came up with the error:

ValueError: invalid literal for int() with base 10: '0.0'

I also tried math.floor, but it ended up telling me that it needs to float.

Any help would be really appreciated!!

0

1 Answer 1

1

If the behavior of int() is what you want, cast to a float first:

int(float(form.getvalue("exposure")))

If you want to be certain of getting one of math.floor() or math.ceil(), you can incorporate those:

int(math.floor(float(form.getvalue("exposure"))))
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.