Jump to content

Only display decimals if they're present


davidcriniti

Recommended Posts

Hi guys,

 

I've got a line of code that asks for a column called "distance_completed" to be displayed as part of a string.

 

This column tells users how far people have run in a running race.

 

I set up this field in my database to 11,3 so all distances appear with a decimal at the end, and then 3 digits after the decimal place.

 

How would I alter the code so that the numbers that don't have any information in the places section just appear as integers Eg: 42 instead of 42.000 (for someone who ran exaclty 42km) and those that do have information in the decimal places appear correctly (eg: if a person ran 42km and 195m, it would appear as 42.195).

 

I think this is probably the only line of code that would need modification:

 


echo ($row['time'] != null)?$row["time"]:"dnf at ".$row["distance_completed"]."km.";

Link to comment
Share on other sites

...but I don't necessarily want to round it off. Eg: If the value was 42.195, I'm happy to keep it that 42.195.

 

I'd only like numbers changed when there is no information on the right-hand-side of the decimal.

 

Eg: If someone ran exactly 20km, I'd like to see 20      ....rather than 20.000

 

Not sure if this is possible or not?

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.