Home > Database > Mysql Tutorial > body text

What is the round function in mysql?

下次还敢
Release: 2024-04-29 03:48:14
Original
419 people have browsed it

The ROUND function in MySQL is used to round numbers. The syntax is ROUND(number, decimal_places), where number is the number to be rounded, and decimal_places is the number of decimal places retained after rounding, such as ROUND( 123.456, 2) Returns the number 123.46 rounded to two decimal places.

What is the round function in mysql?

ROUND Function in MySQL

ROUND function is a function used to round numbers. It takes two parameters:

  • Number: The number to round.
  • Decimal places: The number of decimal places retained after rounding.

Syntax:

<code class="mysql">ROUND(number, decimal_places)</code>
Copy after login

Return value:

ROUND function returns the rounded number.

Usage:

ROUND function is often used to format currency values ​​or other numbers that need to be rounded. For example:

<code class="mysql">SELECT ROUND(123.456, 2);</code>
Copy after login

This will return the number rounded to two decimal places: 123.46.

Example:

The following table shows the ROUND function results for different numbers and decimal places:

##123.4560123 123.4561123.5##123.456123.456##Attention Note:
Number Decimal places Result
2 123.46
3 123.456

If the number of decimal places is negative, the ROUND function will round to integer digits.

    If the number of decimal places is 0, the ROUND function will round to the nearest integer.

The above is the detailed content of What is the round function in mysql?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!