el_quick
el_quick

Reputation: 4746

changing number format with php

I have numbers like these...

1.235,45
100,00
5,5678
25.321,10

But I need those numbers in the following format:

1235.45
100
5.5678
25321.1

Upvotes: 1

Views: 3062

Answers (2)

Karoly Horvath
Karoly Horvath

Reputation: 96258

function cnv($str) {
    $str = str_replace(".", "", $str);
    $str = str_replace(",", ".", $str);
    return (float) $str;
}

Upvotes: 0

Lars
Lars

Reputation: 5799

$number = str_replace('.', '', $number);
$number = str_replace(',', '.', $number);
$number = (float)$number;

Should do the trick.

Upvotes: 3

Related Questions