B
B
bO_oblik2011-10-03 11:44:04
PHP
bO_oblik, 2011-10-03 11:44:04

PHP price parsing?

There are all sorts of options for recording prices:
1000 rubles
1000.00 rubles
1000.00 rubles
And all sorts of others, are there any ready-made solutions for parsing them in float?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
C
cat_crash, 2011-10-03
@cat_crash

Yes,
right on the official PHP website: www.php.net/manual/en/function.preg-match-all.php You
can also try to google

E
Eugene, 2011-10-03
@Agent_J

$str = str_replace(' ', '', $string);
preg_match("#(\d+)(\.|,)?(\d+)?#", $str, $matches); // preg_match_all если много цен в одной строке

M
mark_ablov, 2011-10-03
@mark_ablov

Zend_Number
example:

$locale = new Zend_Locale('de_AT');
$number = Zend_Locale_Format::getNumber('13.524,678',
                                        array('locale' => $locale,
                                              'precision' => 3)
                                       );
 
print $number; // will return 13524.678

S
Sergey Beresnev, 2011-10-03
@sectus

Slightly off topic, but you can’t work with money in floats ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question