njdubois Posted September 11, 2012 Share Posted September 11, 2012 I am creating an excel report that displays a username and their score. These are a few examples of what I am going for : 3.50 4.00 1.45 In the excel report these numbers show as 3.5 4 1.45 or so on... I want the 2 points always shown but everything I find online strips them. I'm not using any features of excel. Just saying put this number here. I'm about to just pad the variable with zeros but am hoping there is a built in function? Thanks for taking a look! Your help is always very appreciated! Nick Quote Link to comment https://forums.phpfreaks.com/topic/268262-keeping-2-decimal-points-even-if-they-are-zeros/ Share on other sites More sharing options...
Jessica Posted September 11, 2012 Share Posted September 11, 2012 use number_format(), and then if excel still doesn't like that, you'll have to make the cell a string by wrapping it in quotes. Quote Link to comment https://forums.phpfreaks.com/topic/268262-keeping-2-decimal-points-even-if-they-are-zeros/#findComment-1377088 Share on other sites More sharing options...
njdubois Posted September 11, 2012 Author Share Posted September 11, 2012 Thanks for the uber fast reply!!! Guess I should have included this. These are the 2 functions I have tried : $current_score=number_format((float)$current_score, 2, '.', ''); $current_score=round($current_score, 2); Your saying that excel is formatting the numbers and that I will have to turn $current_score into a string to stop excel from stripping my numbers? I will take a look. Thanks Nick Quote Link to comment https://forums.phpfreaks.com/topic/268262-keeping-2-decimal-points-even-if-they-are-zeros/#findComment-1377090 Share on other sites More sharing options...
jotorres1 Posted September 11, 2012 Share Posted September 11, 2012 yeap, excel tends to do that. Quote Link to comment https://forums.phpfreaks.com/topic/268262-keeping-2-decimal-points-even-if-they-are-zeros/#findComment-1377109 Share on other sites More sharing options...
Jessica Posted September 11, 2012 Share Posted September 11, 2012 Yep, that's excel. Quote Link to comment https://forums.phpfreaks.com/topic/268262-keeping-2-decimal-points-even-if-they-are-zeros/#findComment-1377111 Share on other sites More sharing options...
requinix Posted September 11, 2012 Share Posted September 11, 2012 Or you could tell Excel to format the number as you want it. Quote Link to comment https://forums.phpfreaks.com/topic/268262-keeping-2-decimal-points-even-if-they-are-zeros/#findComment-1377116 Share on other sites More sharing options...
njdubois Posted September 12, 2012 Author Share Posted September 12, 2012 And those little green triangles it puts in the corner of cells with strings.... Thanks for the help ladies and gents! Nick Quote Link to comment https://forums.phpfreaks.com/topic/268262-keeping-2-decimal-points-even-if-they-are-zeros/#findComment-1377163 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.