Remove decimals from PHP number

0
  

I have the following number: "4.000.00" I need to delete the point and   the two 0 the right in (php 5) thank you!

I tried with:

preg_replace('/^(\d+)\.0+$/', '$1', $this->input->post('valor'));

trim($this->input->post('valor'),0); //solo quita el 00 pero no el "."
    
asked by Javier Antonio Aguayo Aguilar 12.05.2017 в 17:18
source

2 answers

1

Following the example you added, you can delete the decimal point in the same way with trim :

The code would be like this:

trim(trim($this->input->post('valor'),0), '.');
    
answered by 12.05.2017 / 17:43
source
0

Use the number_format function:

$var = 4000.00;
echo number_format($var,0);

Take into account that you should not have a , otherwise you would have problems with the variable, because PHP would try to take it as a string.

    
answered by 12.05.2017 в 17:21