Reputation: 321
How can I remove ,00 from the back of a price? Example: input1: 100.000,00 output1: 100.000
input2: 100.000.00 output2: 100.000
what I've tried is:
preg_replace("/[^(0-9)\.\,(0-9)]/", '', $text)
but it always return 100
Thanks for the help
Upvotes: 0
Views: 478
Reputation: 3714
You can use number_format()
$number = '100.000,00';
echo number_format(floatval($number), 3, '.', '');
Output:
100.000 // same output for '100.000.00'
http://php.net/manual/en/function.number-format.php
Upvotes: 1
Reputation: 28524
You can use substr to remove the last three chars.
substr('100.000,00', 0, -3)
Upvotes: 0
Reputation: 1981
You can try with this pattern
preg_replace('/[\.,]0{2}$/', '', $text);
Notes:
[\.,]
- Matches single period or comma0{2}
- matches the character 0 exactly two times$
- assert position at the end of stringUpvotes: 1