JavaScript? ?? ?? ??
?? ?? ??
?? ??? ?? ??(?? ??)???.
toFixed()
??: ? ?? ??? ?? ???? ????? ???? ???? ??????.
??: numObj.toFixed(n)
????: n? ??? ??? ?? ??????.
?:
var a = 123.9878;
a = a.toFixed(2); // a = "123.99"
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>php.cn</title> <script> var x=134.456756; document.write(x.toFixed(3)); </script> </head> <body> </body> </html>
?: ?? ?? ???
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>php.cn</title> <script> //求圓的面積 function getArea(r){ var s=Math.PI*r*r; s=s.toFixed(4); document.write("半徑為:"+r+"的圓,面積為:"+s+"<br/>"); } getArea(2); getArea(4); getArea(5); </script> </head> <body> </body> </html>