Hobbyist_PHPer Posted September 7, 2012 Share Posted September 7, 2012 Hi, can someone tell me how to determine if a number is a whole or a decimal value number? Quote Link to comment Share on other sites More sharing options...
Jessica Posted September 7, 2012 Share Posted September 7, 2012 As I told you in your other thread, for your purposes it makes more sense to automatically convert to a decimal value of 1.0 or 1.5. If you insist on checking what type it is, there are functions like is_float(), etc. Quote Link to comment Share on other sites More sharing options...
xyph Posted September 7, 2012 Share Posted September 7, 2012 Hi, can someone tell me how to determine if a number is a whole or a decimal value number? Where is this number coming from? Quote Link to comment Share on other sites More sharing options...
Hobbyist_PHPer Posted September 7, 2012 Author Share Posted September 7, 2012 As I told you in your other thread, for your purposes it makes more sense to automatically convert to a decimal value of 1.0 or 1.5. If you insist on checking what type it is, there are functions like is_float(), etc. Right, but don't I still have to then parse it as a string, to get the whole number and the decimal value? Then I'd have to determine if it is .5 or .0, if it is .5 then it would output 30 or if it was 0, it would be 00 Quote Link to comment Share on other sites More sharing options...
Hobbyist_PHPer Posted September 7, 2012 Author Share Posted September 7, 2012 Hi, can someone tell me how to determine if a number is a whole or a decimal value number? Where is this number coming from? a loop, for ($i=1;$i<24.5;$i+=0.5) Quote Link to comment Share on other sites More sharing options...
Jessica Posted September 7, 2012 Share Posted September 7, 2012 You really should have that loop go from 0 to 23.5, 12:30 am is 0.5 Quote Link to comment Share on other sites More sharing options...
Hobbyist_PHPer Posted September 7, 2012 Author Share Posted September 7, 2012 You really should have that loop go from 0 to 23.5, 12:30 am is 0.5 Right, thanks is this what you were talking about with the number format? $i = number_format($i, 2, '.', ' '); Quote Link to comment Share on other sites More sharing options...
Jessica Posted September 7, 2012 Share Posted September 7, 2012 I *think* you can leave the 4th param out since you will never have a number in the thousands, but you want your digits set to 1 based on your other code. But yes that is what I meant. <?php for ($i=0.0;$i<23.5;$i+=0.5){ echo number_format($i, 1).'<br>'; } Quote Link to comment Share on other sites More sharing options...
Jessica Posted September 7, 2012 Share Posted September 7, 2012 Edit: for other thread, sorry. Quote Link to comment 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.