number.toFixed()メソッドは、Numberオブジェクトの数値の小数点以下を四捨五入し、文字列として返すメソッド。
構文
number.toFixed()
戻り値
小数点以下を四捨五入した文字列。
サンプル
<script type="text/javascript">
var $numberObject = new Number( 12345 );
document.write( $numberObject + ': ' );
document.write( $numberObject.toFixed() + '<br />' );
var $numberObject = new Number( 1234.5 );
document.write( $numberObject + ': ' );
document.write( $numberObject.toFixed() + '<br />' );
var $numberObject = new Number( 123.45 );
document.write( $numberObject + ': ' );
document.write( $numberObject.toFixed() + '<br />' );
var $numberObject = new Number( 12.345 );
document.write( $numberObject + ': ' );
document.write( $numberObject.toFixed() + '<br />' );
var $numberObject = new Number( 1.2345 );
document.write( $numberObject + ': ' );
document.write( $numberObject.toFixed() + '<br />' );
var $numberObject = new Number( 0.12345 );
document.write( $numberObject + ': ' );
document.write( $numberObject.toFixed() + '<br />' );
var $numberObject = new Number( 0.012345 );
document.write( $numberObject + ': ' );
document.write( $numberObject.toFixed() + '<br />' );
</script>
var $numberObject = new Number( 12345 );
document.write( $numberObject + ': ' );
document.write( $numberObject.toFixed() + '<br />' );
var $numberObject = new Number( 1234.5 );
document.write( $numberObject + ': ' );
document.write( $numberObject.toFixed() + '<br />' );
var $numberObject = new Number( 123.45 );
document.write( $numberObject + ': ' );
document.write( $numberObject.toFixed() + '<br />' );
var $numberObject = new Number( 12.345 );
document.write( $numberObject + ': ' );
document.write( $numberObject.toFixed() + '<br />' );
var $numberObject = new Number( 1.2345 );
document.write( $numberObject + ': ' );
document.write( $numberObject.toFixed() + '<br />' );
var $numberObject = new Number( 0.12345 );
document.write( $numberObject + ': ' );
document.write( $numberObject.toFixed() + '<br />' );
var $numberObject = new Number( 0.012345 );
document.write( $numberObject + ': ' );
document.write( $numberObject.toFixed() + '<br />' );
</script>
↓↓↓出力結果↓↓↓