12dstring Posted April 27, 2007 Share Posted April 27, 2007 I have a field in my database which has numbers varying from 0.35 to 60000, and when I output them on my php page, I want the decimal places on the small ones to be shown, but without the large ones appearing with them, ie 60000.00. I've tried all of the different formats, float, decimal, double... but they all seem to either cut the decimals off or have them all on. Is there one which automatically cuts off extra zeros after the decimal place? Thanks, Dave Quote Link to comment https://forums.phpfreaks.com/topic/48968-number-formatting-and-decimal-places/ Share on other sites More sharing options...
fenway Posted April 27, 2007 Share Posted April 27, 2007 You need a conditional format... either do this in mysql with a if, or do it on output only. Quote Link to comment https://forums.phpfreaks.com/topic/48968-number-formatting-and-decimal-places/#findComment-239992 Share on other sites More sharing options...
Wildbug Posted April 27, 2007 Share Posted April 27, 2007 You can use an IF statement to control the format used. IF(FLOOR(val)=val,FORMAT(val,0),FORMAT(val,2)) Quote Link to comment https://forums.phpfreaks.com/topic/48968-number-formatting-and-decimal-places/#findComment-239995 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.