poe Posted March 24, 2007 Share Posted March 24, 2007 i have $a = 2012; $b = 3025; $c = $a / $b; if i use: sprintf( "%01.3f", $c) i get 0.665 how do i format the '$c' so i get .665 (drop the '0')? thanks chris Link to comment https://forums.phpfreaks.com/topic/44098-format-a-number/ Share on other sites More sharing options...
Lumio Posted March 24, 2007 Share Posted March 24, 2007 maybe like this: echo substr($c, 1, 3); Link to comment https://forums.phpfreaks.com/topic/44098-format-a-number/#findComment-214135 Share on other sites More sharing options...
jitesh Posted March 24, 2007 Share Posted March 24, 2007 Just check this $num = 0.665; $num_arr = explode(".",$num); echo ".".$num_arr[1]; exit; Link to comment https://forums.phpfreaks.com/topic/44098-format-a-number/#findComment-214136 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.