Numeric Functions

This section describes some commonly used numeric functions like, ABS(), CEILING(), COS(), PI(), RANDOM(), ROUND(), and TRUNCATE().

"ABS(number)" - Returns the absolute value of the specified number.

"CEILING(number)" - Returns the smallest integer value not less than the specified number.

"COS(number)" - Returns the cosine of the specified number.

"PI()" - Returns the value of PI, 3.141592653589793116.

"EXP(number)" - Returns the value of e raise to the power of the specified number.

"FLOOR(number)" - Returns the largest integer value not greater than the specified number.

"GREATEST(list)" - Returns the largest value of the specified list of values.

"LEAST(list)" - Returns the smallest value of the specified list of values.

"RAND()" - Returns a random number between 0 and 1.

"ROUND(number)" - Returns the nearest integer of the specified number.

"ROUND(number, position)" - Returns the rounded value of the specified number at the specified decimal position.

"SIGN(number)" - Returns -1, 0 or 1 if the specified number is negative, zero or positive.

"TRUNCATE(number, position)" - Returns the truncated value of the specified number at the specified decimal position.

Examples of numeric functions, NumericFunctions.sql:

-- NumericFunctions.sql
-- Copyright (c) 2015, HerongYang.com, All Rights Reserved.
--
SELECT PI();
SELECT CEILING(PI());
SELECT FLOOR(PI());
SELECT ROUND(PI(),4);
SELECT TRUNCATE(PI(),4);

Output:

PI()
3.141593
CEILING(PI())
4
FLOOR(PI())
3
ROUND(PI(),4)
3.1416
TRUNCATE(PI(),4)
3.1415

Last update: 2015.

Table of Contents

 About This Book

 Introduction of SQL

 MySQL Introduction and Installation

 Introduction of MySQL Programs

 Perl Programs and MySQL Servers

 PHP Programs and MySQL Servers

 Java Programs and MySQL Servers

 Datatypes and Data Literals

 Operations and Expressions

 Character Strings and Bit Strings

Commonly Used Functions

 Flow Control Functions

 Character String Functions

Numeric Functions

 Date and Time Functions

 Cast Function

 Table Column Types for Different Types of Values

 Using DDL to Create Tables and Indexes

 Using DML to Insert, Update and Delete Records

 Using SELECT to Query Database

 Transaction Management and Isolation Levels

 Locks Used in MySQL

 Defining and Calling Stored Procedures

 Variables, Loops and Cursors Used in Stored Procedures

 Outdated Tutorials

 References

 PDF Printing Version