dagnasty Posted November 1, 2006 Share Posted November 1, 2006 Is it quicker to place a decimal in a number with string manipulation rather than divided by a certain number and round? Quote Link to comment https://forums.phpfreaks.com/topic/25797-quickie-query/ Share on other sites More sharing options...
Orio Posted November 1, 2006 Share Posted November 1, 2006 I cant understand you... Can you give an example maybe?Orio. Quote Link to comment https://forums.phpfreaks.com/topic/25797-quickie-query/#findComment-117805 Share on other sites More sharing options...
gmwebs Posted November 1, 2006 Share Posted November 1, 2006 I would say do the math and then use the round() function.[code]<?php$x = 5/3.5;echo round($x, 2); // 1.43?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/25797-quickie-query/#findComment-117809 Share on other sites More sharing options...
dagnasty Posted November 1, 2006 Author Share Posted November 1, 2006 What if my number is 546000 would it be quicker to divide by 1000 or to insert decimal where I know it goes with string manipulation? Quote Link to comment https://forums.phpfreaks.com/topic/25797-quickie-query/#findComment-117818 Share on other sites More sharing options...
craygo Posted November 1, 2006 Share Posted November 1, 2006 if you want to keep it as a number you should divide it. Numbers are always faster to minipulate than strings.Ray Quote Link to comment https://forums.phpfreaks.com/topic/25797-quickie-query/#findComment-117822 Share on other sites More sharing options...
dagnasty Posted November 1, 2006 Author Share Posted November 1, 2006 The reason I'm asking is because it will be done about 200 times in my script and they are large numbers. Quote Link to comment https://forums.phpfreaks.com/topic/25797-quickie-query/#findComment-117827 Share on other sites More sharing options...
craygo Posted November 1, 2006 Share Posted November 1, 2006 200 times is nothing for a script. I wrote this quick looping 500 times and it returned in less than a second[code]<?php<?for($i=20000; $i<=20500; $i++){$newnumber = ($i / 10.6);echo round($newnumber, 2)."<br>";}?>[/code]So I would say stay with the number formulasRay Quote Link to comment https://forums.phpfreaks.com/topic/25797-quickie-query/#findComment-117833 Share on other sites More sharing options...
gmwebs Posted November 1, 2006 Share Posted November 1, 2006 What about using number_format()?[code]<?php$val = "54600000";echo number_format($val, 0, "", ","); // returns 54,600,000?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/25797-quickie-query/#findComment-117834 Share on other sites More sharing options...
dagnasty Posted November 1, 2006 Author Share Posted November 1, 2006 because it deals with filse size.ex. 23.42 MB3.1 GB32.34 KB Quote Link to comment https://forums.phpfreaks.com/topic/25797-quickie-query/#findComment-117998 Share on other sites More sharing options...
Orio Posted November 1, 2006 Share Posted November 1, 2006 Make a test-make file a.php which uses the math operations and in the begining write- $start=microtime(). In the end write echo ((microtime()-$start)).Then make file b.php which uses round() or whatever, in the beging write $start=microtime() and in the end write echo ((microtime()-$start)). See if there is a real diffrence between the number of seconds that a.php took compared to b.php.Orio. Quote Link to comment https://forums.phpfreaks.com/topic/25797-quickie-query/#findComment-118010 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.