Alicia Posted March 4, 2012 Share Posted March 4, 2012 Hi, May I know how can I remove all characters after the first 3 characters after . e.g : 123.512645124 I want to maintain 123.512 without rounding up. Please advise and thanks. I wanted to use strstr and trim functions but I am not able to use it to get what I want.. can some guru please assist .. thanks again Quote Link to comment https://forums.phpfreaks.com/topic/258254-removing-characters/ Share on other sites More sharing options...
smerny Posted March 4, 2012 Share Posted March 4, 2012 $number = 123.512645124; $number = floor($number * 100) /100; Quote Link to comment https://forums.phpfreaks.com/topic/258254-removing-characters/#findComment-1323790 Share on other sites More sharing options...
sunfighter Posted March 4, 2012 Share Posted March 4, 2012 Without rounding up, using string functions: <?php $number = 123.512645124; $part = explode('.', $number); $part[1] = substr($part[1], 0, 3); $number = implode('.', $part); echo $number; ?> Quote Link to comment https://forums.phpfreaks.com/topic/258254-removing-characters/#findComment-1323803 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.