Numeric Value Functions

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

MySQL supports a number of built-in functions that allows you to manipulate numeric values.

"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) 1999 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

Table of Contents

 About This Book

 Introduction of SQL

 MySQL Introduction and Installation

 Introduction of MySQL Programs

 PHP Programs and MySQL Server

 Perl 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 Value Functions

 Date and Time Functions

 JSON Document Functions

 XML Document Functions

 Spatial Data 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

 Window Functions for Statistical Analysis

 Use Index for Better Performance

 Transaction Management and Isolation Levels

 Locks Used in MySQL

 Defining and Calling Stored Procedures

 Variables, Loops and Cursors Used in Stored Procedures

 System, User-Defined and Stored Procedure Variables

 MySQL Server Administration

 Storage Engines in MySQL Server

 InnoDB Storage Engine - Primary and Secondary Indexes

 Performance Tuning and Optimization

 Bulk Changes on Large Tables

 MySQL Server on macOS

 Installing MySQL Server on Linux

 Connection, Performance and Second Instance on Linux

 Archived Tutorials

 References

 Full Version in PDF/EPUB