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
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.
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.
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.
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.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With