mazman13 Posted October 4, 2007 Share Posted October 4, 2007 Ok I'm writing a CSI program for a body shop and need to be able to take % from the data they receive. This works well: EI: $yes = "30"; $total = "170"; $newtotal = ($yes * 100) / $total; echo"$newtotal%"; Answer is: 17.647058823529411764705882352941% How can I get the answer to just get: 17.6%? Any ideas to limit this string? Thanks Link to comment https://forums.phpfreaks.com/topic/71812-solved-need-help-with-converting-to-dec/ Share on other sites More sharing options...
shocker-z Posted October 4, 2007 Share Posted October 4, 2007 How about this mate? $yes = "30"; $total = "170"; $newtotal = ($yes * 100) / $total; $decimal = round($newtotal, 1); echo"$newtotal%"; Regards Liam Link to comment https://forums.phpfreaks.com/topic/71812-solved-need-help-with-converting-to-dec/#findComment-361663 Share on other sites More sharing options...
Psycho Posted October 4, 2007 Share Posted October 4, 2007 Another option is number_format() $newtotal = number_format( ($yes*100/$total), 1) . '%'; Link to comment https://forums.phpfreaks.com/topic/71812-solved-need-help-with-converting-to-dec/#findComment-361666 Share on other sites More sharing options...
mazman13 Posted October 4, 2007 Author Share Posted October 4, 2007 Works great! Thanks guys Link to comment https://forums.phpfreaks.com/topic/71812-solved-need-help-with-converting-to-dec/#findComment-361675 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.