ฟังก์ชันROUND() ของ เซิร์ฟเวอร์ SQL
ตัวอย่าง
ปัดเศษตัวเลขให้เป็นทศนิยม 2 ตำแหน่ง:
SELECT ROUND(235.415, 2) AS RoundValue;
ความหมายและการใช้งาน
ฟังก์ชัน ROUND() ปัดเศษตัวเลขเป็นจำนวนหลักทศนิยมที่ระบุ
เคล็ดลับ:ดู ฟังก์ชัน FLOOR()และ CEILING()ด้วย
ไวยากรณ์
ROUND(number, decimals, operation)
ค่าพารามิเตอร์
Parameter | Description |
---|---|
number | Required. The number to be rounded |
decimals | Required. The number of decimal places to round number to |
operation | Optional. If 0, it rounds the result to the number of decimal. If another value than 0, it truncates the result to the number of decimals. Default value is 0 |
รายละเอียดทางเทคนิค
ทำงานใน: | SQL Server (เริ่มตั้งแต่ปี 2008), ฐานข้อมูล Azure SQL, Azure SQL Data Warehouse, Parallel Data Warehouse |
---|
ตัวอย่างเพิ่มเติม
ตัวอย่าง
ปัดเศษตัวเลขให้เป็นทศนิยม 2 ตำแหน่ง และใช้ พารามิเตอร์การทำงาน ด้วย:
SELECT ROUND(235.415, 2, 1) AS RoundValue;
ตัวอย่าง
ปัดเศษตัวเลขให้เป็นทศนิยม -1 ตำแหน่ง:
SELECT ROUND(235.415, -1) AS RoundValue;