- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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
Advertisements