How to convert int (integer) type to decimal in php

青灯夜游
Release: 2023-03-15 14:36:01
Original
3006 people have browsed it

Conversion method: 1. Use the number_format() function, the syntax "number_format (int type value, number of decimal places)"; 2. Use the sprintf() function, the syntax "sprintf("%.xf", value of type int)", the parameter x is the number of decimal places.

How to convert int (integer) type to decimal in php

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

php will int ( Integer) type to decimal

Method 1: Use the number_format() function

number_format() can format numbers by thousands grouping .

<?php
echo number_format(12,1)."<br>";
echo number_format(12,2)."<br>";
echo number_format(12,3)."<br>";
echo number_format(12,4)."<br>";
?>
Copy after login

How to convert int (integer) type to decimal in php

Method 2: Use sprintf() function

sprintf() function writes the formatted string into a variable middle.

<?php
echo sprintf("%.1f",12)."<br>";
echo sprintf("%.2f",13)."<br>";
echo sprintf("%.3f",14)."<br>";
echo sprintf("%.4f",15)."<br>";
?>
Copy after login

How to convert int (integer) type to decimal in php

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to convert int (integer) type to decimal in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template