$string_with_no_commas = number_format($price, 2, '.', '')
'' is two ' and not "
That should do it. Methinks it's the implicit conversion when you add the two prices that's at fault.
I also ltrim and rtrim the input string just in case.
Use switch/case instead of loads of if/else
I really wouldn't use Javascript - if the user disables Javascript then your site probably won't work. Client side data formatting and verification is for speed only - should always implement the same measures server side too.