Formatting math data returned by MySQL table
Where X is the data and D is the number of places after the decimal required.
For example in a table we are storing number of rating given by visitors. Here we are strong the total rating and the number of visitors submitted the rating. These two fields are required to get the average rating the article got. We will simply divide total score by total number of ratings given to get the average rating. Here the result of this ratio we will format for our requirement.
Here score is the field name where we are storing total score given by the visitors. Same way nov field stores the number of votes submitted by visitors.
We can format our data while updating or inserting to a table. In the same table above we will try to update one more field avg_score by using values of score and nov fields.
Here we have formatted the decimal place to three places. Inside the query avg_score, score and nov are field names and they are integer and float type fields.
You can read MySQL date format here. Subscribe to our YouTube Channel here
This article is written by plus2net.com team.
https://www.plus2net.com
