Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

append decimal point in the middle of integer in postgres

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading