Jump to content

How to determine if a number is whole or decimal


Hobbyist_PHPer

Recommended Posts

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

Link to comment
Share on other sites

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>';
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.