Problems with number_format (PHP) by colon in numeral

2

I'm having problems with the number_format function of PHP, since my numeral comes from the database with two points, eg:

  

1.235.32

I'm using number_format this way:

number_format(floatval('1.235.32'), 2, ',', '.');

And it turns out this:

  

1.22

I need my result to be formatted like this:

  

1235.32

    
asked by anonymous 21.12.2016 / 19:53

2 answers

1

If you can not change the data input, use this solution:

// Elimina a pontuação
$value = str_replace('.', '', '100.235.32');

// Adiciona a pontuação correta
$value = substr_replace($value, '.', strlen($value) - 2, 0);

echo number_format($value, 2, ',', '.');

substr_replace - Replace text within a part of a string

    
21.12.2016 / 20:51
0

Do the following, would that be?:

 substr(str_replace('.','','1.235.32'),0,strlen(str_replace('.','','1.235.32'))-2).".".substr('1.235.32',-2);

Half the gabiarra but I think that's it ... I hope I have helped !!

    
21.12.2016 / 20:34