<!DOCTYPE HTML> <html lang="ja-JP"> <head> <meta charset="UTF-8"> <title></title> </head> <body> </body> <script type="text/javascript"> var data = 1254.56789; var str = ""; str += Math.round(data) + "<br>"; str += Math.round(data * 100) / 100 + "<br>"; str += Math.round(data * 10000) / 10000 + "<br>"; str += Math.round(data / 100) * 100 + "<br>"; document.getElementsByTagName("body")[0].innerHTML = str; </script> </html>
<?php header("Content-type: text/html; charset=utf-8"); $data = 1254.56789; //小数点以下を四捨五入 echo round($data) . "<br>"; //小数第2位を四捨五入 echo round($data * 100) / 100 . "<br>"; //小数第4位を四捨五入 echo round($data * 10000) / 10000 . "<br>"; //百の位を四捨五入 echo round($data / 100) * 100 . "<br>"; ?>