揮発性のメモ2

http://d.hatena.ne.jp/iww/

小数点以下の桁数を指定して表示する

123456 を 123456.00 みたいに小数点以下の桁数を指定して表示する

var a = 123456;
var n = 2;
console.log( a.toFixed(n) ); // 123456.00

Number.prototype.toFixed() - JavaScript | MDN

<?
$a = 123456;
$n = 2;
print number_format($a, $n, ".", ""); // 123456.00

PHP: number_format - Manual

double a = 123456;
int n = 2;

printf("%.*lf\n", n, a); // 123456.00

Man page of PRINTF