
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
How to display two decimals in MySQL/PHP?
To display two decimals, use number_format(). Let us first write the PHP code for the same. We have first declared two variables are initialized −
$number1=10.3423; $number2=10;
Now, display the two decimals using the number_format() function −
$result1=number_format ($number1, 2); $result2=number_format ($number2, 2);
Example
Following is the example −
<?php $number1=10.3423; $number2=10; $result1=number_format ($number1, 2); $result2=number_format ($number2, 2); echo ($result1); echo '<br>'; echo ($result2); ?>
Output
Following is the snapshot of PHP code −
10.34 10.00
- Related Articles
- How to display errors in PHP file?
- How to display XML in HTML in PHP?
- Calculate average of column values and display the result with no decimals in MySQL
- How to format a number with two decimals in JavaScript?
- How to write PHP script by using MySQL JOINS inside it to join two MySQL tables?
- Display a two-dimensional array with two different nested loops in matrix form PHP?
- How to display two different sums of the same price from column Amount in MySQL?
- Display records with more than two occurrences in MySQL?
- How to display current connection info in MySQL?
- How to compare decimals ?
- How to simplify decimals?
- How to multiply decimals?
- Display records from two columns based on comparison in MySQL?
- How to display records vertically in MySQL command line?
- How to display some columns (not all) in MySQL?

Advertisements