We've had to develop an internal tool that parses invoice files and extracts their totals.
It seems a French company used a comma as a decimal separator. It was confusing at first.
e.g. 9,99 EUR means 9.99 EUR.
Normally a comma is used to separate the thousands and make the number look more readable.
It's easier to read $1,000,000.00 vs 1000000.00.
If you're sending money to somebody there's a huge difference if you add an extra 0 at the end.
If you're on the receive end though it would be nice to get an extra zero.
// https://orbisius.com/6473
// Let's first check if there's a comma at all
if (strpos($val, ',') !== false) {
$val = preg_replace('#[\.\,\s]+(\d{2})$#si', '.${1}', $val);
// cases; 1,500, 1,500.00
// Now we can remove the commas as separators e.g. 1,000,000 -> 1000000
$val = str_replace( [ ' ', ','], '', $val); // space or comma as thousands sep?
}
Referral Note: When you purchase through a referral link (if any) on this page, we may earn a commission.
If you're feeling thankful, you can buy me a coffee or a beer