Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8910965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:49:38+00:00 2026-06-15T03:49:38+00:00

In SQL Server 2005 str() behaves strange on some float values while rounding. While

  • 0

In SQL Server 2005 str() behaves strange on some float values while rounding. While searching in net, I found the below code and explanations there.

select STR(4.65,5,1) -- it will give 4.7
select STR(3.65,5,1) -- it will give 3.6

I got some explanations here and here, but didn’t get anything from there (that above T-SQL taken from one of the explanations link)

Could anyone please explain why it behaves like this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T03:49:39+00:00Added an answer on June 15, 2026 at 3:49 am

    Syntax of STR(); STR ( float_expression [ , length [ , decimal ] ] ) clearly says that the number is a float_expression. Therefore whatever the number you give it will be first converted to a FLOAT(n) where default value of n = 53.

    So

    SELECT STR(4.65,5,1), SELECT STR(3.65,5,1)  
    

    Equal to:

    SELECT STR(CAST(4.65 AS FLOAT(53)),5,1) , STR(CAST(3.65 AS FLOAT(53)),5,1)
    

    If you specify n, say n = 4 it will give the answer you are expecting (ie; 4.7 and 3.7)

    SELECT STR(CAST(4.65 AS FLOAT(4)),5,1) , STR(CAST(3.65 AS FLOAT(4)),5,1)
                  --4.7,                     3.7
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to log some param values to a log file (SQL Server 2005)
SQL Server 2005/2008, db=user=schema=owner='John', ASP.net 2.0.50727, vb, IIS7 I'm moving website from one server
I've got a SQL Server 2005 database. I need to get distinct values in
SQL Server (2005/2008) Each of the below statements have the same result. Does anyone
In sql server 2005, how do I get the result set in table3 below?
Using SQL Server 2005 Full Text Search I'd like to return values within a
SQL Server 2005 BOL says about BREAK: Exits the innermost loop in a WHILE
SQL Server 2005 I have an SQL Function (ftn_GetExampleTable) which returns a table with
SQL Server 2005 Profiler shows that a Stored Procedure (SP) was called and what
SQl Server 2005: Option: 1 CREATE TABLE #test (customerid, orderdate, field1 INT, field2 INT,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.