ERuiz Posted October 31, 2007 Share Posted October 31, 2007 Hello guys and gals, Please don't laugh, since I know this will be an easy question, but how can I make this value: $fuel = "19312.92"; end up looking like this: $fuel = "193"; And if possible, always insert a ZERO in front of the result, so that it ends up looking like this: $fuel = "0193"; Ok, stop laughing now. LMAO! Thanks for any help as always! Quote Link to comment https://forums.phpfreaks.com/topic/75445-solved-rounding-a-number/ Share on other sites More sharing options...
cooldude832 Posted October 31, 2007 Share Posted October 31, 2007 that isn't rounding that is a unit conversion You taking it and dividing it by 100 and then rounding it <?php $num = 19312.92; $num = round($num/100); ?> then i'll let you look at sprintf() to figure out how to get the padding. Quote Link to comment https://forums.phpfreaks.com/topic/75445-solved-rounding-a-number/#findComment-381661 Share on other sites More sharing options...
ERuiz Posted October 31, 2007 Author Share Posted October 31, 2007 that isn't rounding that is a unit conversion You taking it and dividing it by 100 and then rounding it <?php $num = 19312.92; $num = round($num/100); ?> then i'll let you look at sprintf() to figure out how to get the padding. THANKS!!! I really appreciate it! Quote Link to comment https://forums.phpfreaks.com/topic/75445-solved-rounding-a-number/#findComment-381663 Share on other sites More sharing options...
ERuiz Posted October 31, 2007 Author Share Posted October 31, 2007 then i'll let you look at sprintf() to figure out how to get the padding. I didn't want to let you down, so here it is: $fuel = sprintf("%04d", $fuel); Quote Link to comment https://forums.phpfreaks.com/topic/75445-solved-rounding-a-number/#findComment-381671 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.