CodeIgniter Forums
Database Decimal Value - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Database Decimal Value (/showthread.php?tid=28789)



Database Decimal Value - El Forum - 03-22-2010

[eluser]JamesTaylor[/eluser]
I'm storing some numeric data which will usually be whole numbers, but on a few occassions it may be a decimal.

At the moment i have the DB field set to 'Decimal(5,2)'

When i display the values on my page it always shows the decimal, but if its a whole number i would prefer it just to display as a whole number without the deciaml places...

i.e:
72 should display as 72 not 72.00
72.35 should display as 72.35

is there a way to achieve this whilst still using a numeric data type, i'm quite happy to change the datatype to INT / FLOAT etc if needed.

Otherwise i thought perhaps it would be best just to have the datatype as varchar - as it stands i can't see any numeric opperations being required on the values as they are just final scores from golf competitions... but equally i don't want to rule out the ability if i don't have to.

Thanks

James


Database Decimal Value - El Forum - 03-22-2010

[eluser]mattpointblank[/eluser]
http://php.net/manual/en/function.round.php


Database Decimal Value - El Forum - 03-22-2010

[eluser]JamesTaylor[/eluser]
Thanks matt but i don't think thats what i'm looking for... i don't want anything to be rounded up or down, i just don't want to display the .00 if a number is 73.00 for example - if its 73.01 then it should display as 73.01.

what i'm looking for is a way to omit .00 and only .00 i guess


Database Decimal Value - El Forum - 03-22-2010

[eluser]mattpointblank[/eluser]
Code:
$int = '6.00';
echo floor($int);

(I'm in Leeds by the way, hello!)


Database Decimal Value - El Forum - 03-23-2010

[eluser]JamesTaylor[/eluser]
Thanks Matt, yeah i'm not too far from Leeds - good to see there's some locals on here too!