Home > other >  append decimal point in the middle of integer in postgres
append decimal point in the middle of integer in postgres

Time:04-22

I'm doing a report from our database regarding some amount

It shows like this in the report from the front end

enter image description here

however in the backend it's like this

enter image description here

It seems that the system adds a decimal point before the last two digits of the entries I've check the other ones and this seems to be the case

My question is, is there a function that I can use to append a decimal point before the last two digits whenever I generate the report in postgres?or is there another way to achieve the same result?

So I can provide a backend report that shows the same as the front end

CodePudding user response:

Assuming the amount values are actually in cents, you should be able to just divide by 100:

SELECT expense_date, CAST(amount / 100.0 AS money) AS money
FROM yourTable;

Also, you may wish to handle this formatting issues in your presentation layer rather than directly on Postgres.

  • Related