Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

difference of format and round mysql

i would like to know if there is a difference between round((first + second + third + fourth)/4,2) and format((first + second + third + fourth)/4,2),

i tried it in my database but I didnt see a difference, i'm working on a project that needs to be precise

thanks in advance

like image 731
makoto Avatar asked Aug 29 '13 04:08

makoto


People also ask

What is format in MySQL?

The FORMAT() function formats a number to a format like "#,###,###. ##", rounded to a specified number of decimal places, then it returns the result as a string.

What is ROUND in MySQL?

MySQL ROUND() Function The ROUND() function rounds a number to a specified number of decimal places. Note: See also the FLOOR(), CEIL(), CEILING(), and TRUNCATE() functions.

What is the difference between ROUND and truncate in MySQL?

ROUND() function rounds the number up or down depends upon the second argument D and the number itself(digit after D decimal places >=5 or not). TRUNCATE() function truncate the number up to D number of decimal places without checking whether the digit after D decimal >=5 or not.

What is the difference between ROUND () and truncate ()?

Rounding a number in the range [2.5, 3.5) returns the number 3. Truncating a number in the range [3.0, 4.0) returns the number 3.


1 Answers

Rounds the argument X to D decimal places. The rounding algorithm depends on the data type of X. D defaults to 0 if not specified. D can be negative to cause D digits left of the decimal point of the value X to become zero.

-->ROUND(X,D)

Formats the number X to a format like '#,###,###.##', rounded to D decimal places, and returns the result as a string. If D is 0, the result has no decimal point or fractional part. D should be a constant value.

--> FORMAT(X,D)
like image 64
jainvikram444 Avatar answered Oct 03 '22 11:10

jainvikram444