Share via

Query help for rounding off

antony joseph 61 Reputation points
2021-06-28T13:40:54.85+00:00

Dear Experts

Please help in converting below amount field into two decimals.

For the below query i tried it is getting rounding off

SELECT CAST (105798/ 100 AS DECIMAL (25,2))

Expected result

1057.98

But I am getting result as 1057.00

Please help experts.

Developer technologies | Transact-SQL
Developer technologies | Transact-SQL

A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.

0 comments No comments

Answer accepted by question author

Olaf Helper 47,621 Reputation points
2021-06-28T13:44:37.983+00:00

But I am getting result as 1057.00

You calculate with integer values and so you get integer as result = no decimals. Convert the value to numeric value, e.g. simply multiply with 1.0

SELECT CAST (1.0 * 105798/ 100 AS DECIMAL (25,2))

Was this answer helpful?

0 comments No comments

1 additional answer

Sort by: Most helpful
  1. antony joseph 61 Reputation points
    2021-06-28T13:51:14.287+00:00

    Thank you so much and it helped me much and worked awesome.

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.