Take only the value and format in 2 decimal places

Asked

Viewed 3,233 times

-1

Well, I have a python script that queries two different databases to verify values per day, one in SQLSERVER and the other in Postgres.

I used an if to warn if the values were different and if it is, warn.

What happens and what was alarming even I consulting in the base that they were equal.

When printing the result of the variables of the script I came across this inserir a descrição da imagem aqui

How do I get value only, without decimal and character information and format for only 2 decimal places?

  • Those two lines you posted that were compared to each other? Did you notice that the first is a list and the second is a tuple? Couldn’t that be the problem?

  • And if you want to compare, and the data is interpreted as float, you don’t use equality, and yes valor-absoluto(a-b) < 0.0000...0001 (acceptable accuracy), or simply take the data as integers. (although, looking at the Decimal class, probably its error is in if and has nothing to do with what was described in the question)

  • 1

    On Bacco’s commentary, there is math.isclose which may be used for such a purpose.

  • The way it is, we don’t have enough data to help. Click on [Edit] and post the comparison code so we can understand the problem and the complete output of your debug in text, not image, so the community can help more objectively.

1 answer

1

cast(seu_campo AS NUMERIC(15, 2))
  • Remembering that instead of the 15 you adapt to the size you need.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.