Home > T-SQL > SQL SERVER – Pi π – SQL Math Functions @SQLSERVER

SQL SERVER – Pi π – SQL Math Functions @SQLSERVER


It is a mathematical constant number to represent the ratio of a circle’s circumference to its diameter. The value of Pi is approximately equal to 3.14159. It is actually an irrational number. 22/7 is also another form of Pi value. In computer programming we usually use this as a constant number as 3.1415 or with more decimal values. There is a history behind this Pi. You can read more about it in Wikipedia.

I watched a movie named Pi. A mathematician try to discover a number using his home-made supercomputer to unlock some of the universal pattern. You can learn about that movie here. it is nothing to do with this blog post. But, I am interested in mentioning here.

In SQL Server

Pi() is a mathematical function that returns a constant float value of math Pi.

Example

Select pi()
Output: 3.14159265358979
 
T-SQL to get Pi value
 
declare @Pi as float = 22/7
select @Pi
go;
Output: 3
 
declare @Pi as float = 22.0/7.0
select @Pi
go;
Output: 3.142857
 

The output of these two T-SQL  is different from the PI constant value. PI is denoted as 22/7 and its value is 3.14159 and it is not the value of 22 divided by 7. Because, it is an approximation for Pi.

If you are not too much worried about Pi then just use the Pi() function in your code.

Thanks for reading.

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: