Want to disable rounding in SSMS settings

Bob-7209 66 Reputation points
2022-11-08T16:53:56.35+00:00

Is there a way to disable numeric rounding for the query results in my SSMS settings? For example, my query returns a value of 2.6. This is misleading because when I export the results to a flat file, the value is 2.55555555555. I would like to know this what my client will see on the file I send them so that I can fix it in the query.

I am using Windows 10 Enterprise OS Build 19044.2130 64 bit & SSMS v18.12.1.

SQL Server | Other
{count} votes

Answer accepted by question author
  1. Viorel 125.7K Reputation points
    2022-11-08T20:13:58.85+00:00

    To adjust the behaviour, try this query in SSMS:

    select format(NumericValue, 'G17')  
    from ███████  
    

    Do not use the format function in SSIS if not needed.


2 additional answers

Sort by: Most helpful
  1. Bob-7209 66 Reputation points
    2022-11-08T19:21:04.713+00:00

    Here is an example. The NumericValue field is a float data type. I am trying to just cut the value off after the first decimal place without rounding it. So the end result for this record should be 6.5.

    258390-image.png

    I added a CAST AS VARCHAR to my CASE. I also tried moving this query to a CTE that feeds only the casted varchar values into my larger query, but get the same results.

    258441-image.png

    My query results show everything looking fine, but this is the value going to my flat file.

    258329-image.png


  2. Erland Sommarskog 128.7K Reputation points MVP Volunteer Moderator
    2022-11-08T22:55:13.227+00:00

    In addition to other answers:

    Float is an approxamite data type. Or more precisely it consists of a mantissa of 53 bits and an exponent. Converting this value to decimal can in most cases not be done exactly. And the same goes for converting to string.

    There are more than one library for converting float to string. SSMS uses .NET, which is less zealous with showing decimal. In SSIS, you can select which API to use, but I believe OLE DB is the most common, and this is native code. This library is more prone to show extra decimals.


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.