Jump to content

Recommended Posts

Can someone clear up my confusion about FLOAT.

 

I have data in a TINYINT field that displays whole numbers WITHOUT any decimal places.  This does not format very nicely when there are ALSO decimalled values to be echoed:

  1

1.5

  2

2.5, etc.    It can be a little confusing.

 

The only way I've thought of to resolve the issue (if you know another, please share) is to add a decimal place to get:  1.0

                                            1.5

                                            2.0

                                            2.5 etc.

 

But I am unclear on WHERE to put the commands to get this result.

 

Does it go into the actual DB?  Or into my PHP script?

 

Please help with a detailed example.  Thanks

Link to comment
https://forums.phpfreaks.com/topic/259149-a-question-about-float/
Share on other sites

I'm curious, could you also type cast the numbers? 

 

If you want to display leading or tailing zeros (eg, 2.50 vs 2.5) then you have to cast the number to a string, apply the extra zeros, then output it.

 

For displaying a number to a certain decimal point value, number_format will handle this easily.  If you want leading zero's you'd use str_pad or sprintf.

 

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.