title: Accepting international numbers with decimal and thousands separator in PHP
body: <p>For an online calculator where users may enter an energy amount to calculate corresponding fees, I need the PHP script to accept various user inputs. The value of "2 million and one fourth joule" may be entered as:</p>
  
  <p>2000000.25 (default notation)</p>
  
  <p>2,000,000.25 (with thousands separator)</p>
  
  <p>2000000,25 (comma as decimal point)</p>
  
  <p>2.000.000,25 (comma as decimal point, with thousands separator)</p>
  
  <p>2'000'000.25 (alternative format)</p>
  
  <p>2 000 000,25 (French notation)</p>
  
  <p>How could I make the script aware of such differences?</p>
  
  <p>My first try was to just str_replace alternative characters with the default ones, but the period (.) may be either a decimal or a thousands separator. I tried using sscanf but how can I make sure that it reads the number correctly?</p>
  
  <p>Most users will only provide two digits after the decimal point, but is there any way I can distinguish 1.234 (1 point 234, period as decimal separator) and 1.234 (one thousand two hundred thirty-four, period as thousands separator)? </p>