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! 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. 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! 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); Link to comment https://forums.phpfreaks.com/topic/75445-solved-rounding-a-number/#findComment-381671 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.