php - Remove the currency format using regular expression -
i trying find piece of regex remove currency format.
i have 2 types of currency values. 1 in usd format 1,000.00 , other in eur 1.000,00. need save value in db removing both comma , dot 1000.00
for example if user enter value in usd 2,222.65, need replace 2222.65,
if user enter value in eur 2.222,65 need replace 2222.65,
instead of complex regex, use numberformatter::parse
available php 5 >= 5.3.0, pecl intl >= 1.0.0
.
// german format $fmt = new numberformatter( 'de_de', numberformatter::decimal ); $num = "1.234.567,891"; echo $fmt->parse($num)."<br>\n"; // usd format $fmt = new numberformatter( 'en_us', numberformatter::decimal ); $num = "9,876,543.012"; echo $fmt->parse($num)."<br>\n";
output:
1234567.891 9876543.012
Comments
Post a Comment