Jump to content

tezuya

New Members
  • Content Count

    3
  • Joined

  • Last visited

Community Reputation

0 Neutral

About tezuya

  • Rank
    Newbie
  1. Thank again for your detailed answer. I'd would only add that the end user in our case will be presented with the option to choose which European format to use. For the reason expressed above, I cannot implement too many assumptions about dots coming before comma or similar hard coded logic. The user is the owner of his own data in my case. He knows how to cope with his own problem after all. (ie. it_IT, en_US, etc.) Regards.
  2. Yes Psycho, it's probably the wrong way to cope with a similar problem. My approach in this case will be to use NumberFormatter::Parse passing a specific locale such as it_IT in my case. Anyway, If and only if I will be in the situation requiring to implement a specific RegEx solution, in order to develop more robust data munging routines, my solution is going to be like the following: $num = '4.335,67'; $fmt = numfmt_create( 'it_IT', NumberFormatter::DECIMAL ); if (is_numeric(preg_replace('/(?<=[\d])[\.,]/','${1}', $num))) echo $fmt->parse($num); else echo "Wrong input!"; Please note that you either need to have PHP 5.3 > or you need to install it via PECL intl package 1.0.0. PHP 5.3+ has the support built in. Also have look to php.ini file to enable intl itself. Regards.
  3. Hello Everyone, In the process of displaying currency numbers format from the text file, I was using below regular expression which accepts a string like '12.345,67' and should be ok to match any arbitrary number of three (or less) consecutive digits separated by dot before decimal comma separator is matched. Regular Expression : $_num = preg_replace('/^([0-9]{1,3}\.([0-9]{3}\.)*[0-9]{3}|[0-9]+)(?|,(\d\d))$/', '${1}.${3}', $num) Can anyone tell me what would be the regular expression if I would like to discard the dot character in the above explained case? For the record the mentioned example returns '12.345.67' since the actual regular expression swallow the dot digits separator too. Hopefully you may suggest me a regular expression replacement returning: '12345.67'. With Regards, Tezuya.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.