I need to round a result number,by precision; Example: Math : y=x/1000000; x=5 => y=0.000005, but if I do this in java script y=0.00000500001;(not right) ;how do I round a equation by precision to have a math result
On this page: http://www.merlyn.demon.co.uk/js-rndg3.htm you'll find several methods (arithmetics, strings manipulations, ...)
<script language="javascript"> function php_like_round( num, pre ) { var temp = '1'; for( i = 0 ; i < pre; i++ ) { temp += '0'; } return Math.round( num * temp )/ temp ; } document.write( php_like_round( '4039.23344534534', '2' ) ); </script> HTML: that works .....