Home  >  Article  >  Backend Development  >  Example of keeping two decimal places in JS and PHP. Use function toFixed() for rounding_PHP tutorial

Example of keeping two decimal places in JS and PHP. Use function toFixed() for rounding_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:43:291170browse

JS example of retaining two decimal places and rounding using the function toFixed()






< ;body>

php example of rounding to two decimal places

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 has ¥%01.2f.",$name, $money);
echo $formatted;
//Zhang San has ¥123.10.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/478833.htmlTechArticleJS retaining two decimal places example rounding using function toFixed() html head /head script language="javascript" document. write("h1JS retain two decimal places example/h1br"); var a=2.1512131231231...
Statement:
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