संख्याओं को राउंड और ट्रंकेट करना

इंटरमीडिएट SQL Server

Ginger Grant

Instructor

T-SQL में संख्याओं को राउंड करना

ROUND(number, length [,function])
इंटरमीडिएट SQL Server

T-SQL में संख्याओं को राउंड करना

SELECT DurationSeconds, 
ROUND(DurationSeconds, 0) AS RoundToZero, 
ROUND(DurationSeconds, 1) AS RoundToOne
FROM Incidents
+--------------------+------------------+------------------+     
|DurationSeconds     |RoundToZero       |RoundToOne        |     
+--------------------+------------------+------------------+     
|121.6480            |122.0000          |121.6000          |
|170.3976            |170.0000          |170.4000          |
|336.0652            |336.0000          |336.1000          |
...
+--------------------+------------------+------------------+
इंटरमीडिएट SQL Server

दशमलव के बाएँ तरफ राउंड करना

SELECT DurationSeconds, 
ROUND(DurationSeconds, -1) AS RoundToTen, 
ROUND(DurationSeconds, -2) AS RoundToHundred
FROM Incidents
+--------------------+------------------+------------------+     
|DurationSeconds     |RoundToTen        |RoundToHundred    |     
+--------------------+------------------+------------------+     
|121.6480            |120.0000          |100.0000          |
|170.3976            |170.0000          |200.0000          |
|336.0652            |340.0000          |300.0000          |
...
+--------------------+------------------+------------------+
इंटरमीडिएट SQL Server

संख्याओं को ट्रंकेट करना

ट्रंकेट

17.85 $\rightarrow$ 17

राउंड

17.85 $\rightarrow$ 18

इंटरमीडिएट SQL Server

ROUND() से ट्रंकेट करना

ROUND() फंक्शन का उपयोग तीसरा आर्ग्युमेंट देने पर मानों को ट्रंकेट करने के लिए किया जा सकता है.

ROUND(number, length [,function])
  • तीसरे मान को non-zero पर सेट करें
इंटरमीडिएट SQL Server

T-SQL में ट्रंकेट करना

SELECT Profit, 
ROUND(DurationSeconds, 0) AS RoundingtoWhole, 
ROUND(DurationSeconds, 0, 1) AS Truncating 
FROM Incidents
+--------------------+------------------+------------------+    
|Profit              |RoundingtoWhole   |Truncating        |
+--------------------+------------------+------------------+  
|15.6100             |16.0000           |15.0000           |
|13.2444             |13.0000           |13.0000           |
|17.9260             |18.0000           |17.0000           |
...
+--------------------+------------------+------------------+  

ट्रंकेट करने पर निर्दिष्ट अंक के बाद के सभी अंक हट जाते हैं.

इंटरमीडिएट SQL Server

अभ्यास करते हैं!

इंटरमीडिएट SQL Server

Preparing Video For Download...