Home > php教程 > php手册 > body text

php保留小数和toFixed的用法

WBOY
Release: 2016-06-06 19:46:30
Original
2792 people have browsed it

欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入 php保留小数和js四舍五入函数toFixed的用法: html head /head script type="text/javascript" document.write("h1php保留小数和js四舍五入函数toFixed的用法-php自学网/h1br"); var a=2.151213123123

欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入

  php保留小数和js四舍五入函数toFixed的用法:

  

  

  

  document.write("

php保留小数和js四舍五入函数toFixed的用法-php自学网


");

  var a=2.1512131231231321;

  document.write("原来的值:"+a+"
");

  document.write("两位小数点:"+a.toFixed(2)+"
四位小数点"+a.toFixed(4));

  

  

  

  

  php保留两位小数例子 - 四舍五入

  1.number_format

  $number = 1234.5678;

  $nombre_format_francais = number_format($number, 2, ',', ' '); // 1 234,57

  $english_format_number = number_format($number, 2, '.', ''); // 1234.57

  2.round

  $number = 1234.5678; echo round($number ,2); //1234.57

  3.sprintf

  $formatted = sprintf ("%s有¥%01.2f。",$name, $money);

  echo $formatted; //张三有¥123.10。

php保留小数和toFixed的用法

Related labels:
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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!