Tuesday, 2 August 2016

TRUNCATE: Truncate decimal number



TRUNCATE(number, digits): Truncate the digits after decimal point.

mysql> SELECT TRUNCATE(10.2345, 0);
+----------------------+
| TRUNCATE(10.2345, 0) |
+----------------------+
|                   10 |
+----------------------+
1 row in set (0.00 sec)

mysql> SELECT TRUNCATE(10.2345, 1);
+----------------------+
| TRUNCATE(10.2345, 1) |
+----------------------+
|                 10.2 |
+----------------------+
1 row in set (0.00 sec)

mysql> SELECT TRUNCATE(10.2345, 2);
+----------------------+
| TRUNCATE(10.2345, 2) |
+----------------------+
|                10.23 |
+----------------------+
1 row in set (0.00 sec)

mysql> SELECT TRUNCATE(10.2345, 3);
+----------------------+
| TRUNCATE(10.2345, 3) |
+----------------------+
|               10.234 |
+----------------------+
1 row in set (0.00 sec)

mysql> SELECT TRUNCATE(10.2345, 4);
+----------------------+
| TRUNCATE(10.2345, 4) |
+----------------------+
|              10.2345 |
+----------------------+
1 row in set (0.00 sec)

mysql> SELECT TRUNCATE(10.2345, 5);
+----------------------+
| TRUNCATE(10.2345, 5) |
+----------------------+
|             10.23450 |
+----------------------+
1 row in set (0.00 sec)






Previous                                                 Next                                                 Home

No comments:

Post a Comment