STR() Function in SQL Server

The STR() function converts a numeric value to a character value.

Syntax :

STR(float_expression [, length [, decimal]])

Parameter : This method accepts three parameters as mentioned above and described below :

  • float_expression : It is a numeric expression that evaluates to an approximate number with a decimal point.
  • length : It is the total length of the returned string.
  • decimal : It is the number of places to the right of the decimal point.

Returns : It returns a number as a string.

Example-1 :



SELECT STR(246.573, 6, 2);

Output :

246.57



Example-2 :

SELECT STR(246.573, 3, 3);

Output :

246



Example-3 :

SELECT STR(246.573, 2, 2);

Output :

**



Example-4 :

SELECT STR(246.573, 8, 4);

Output :

246.5730
My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.