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

WBOY
Release: 2016-07-13 17:43:29
Original
1199 people have browsed it

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...
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