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

How do I round a number to two decimals in SQL commander in DBV?

I am dividing two numbers, where numerator is smaller than denominator. I was expecting some numbers between 0 and 1 but I always get 0 without any decimals. I would like to see at least one decimal. I tried the round function but it isn’t working for me. What should I do?

Edit: the two numbers are integers in millions.

I tried round function but it didn’t do the trick.

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

>Solution :

Most likely your numbers are integers, so if you try to divide them it will be integer division. To get around this you need to cast one (or both) of your numbers to a decimal data type:

SELECT CAST(your_numerator AS DECIMAL(10, 2)) / your_denominator AS rounded_value
FROM your_table;

The DECIMAL(10, 2) function means you can store numbers with up to 10 digits in total, where 2 of those digits are reserved for the decimal part, e.g. 12345.67 (10 digits in total, 2 decimal places)`. Obviously you can change these numbers if you want more decimal places.

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