Format decimal places in PHP using semicolon [duplicate]

1

I have a payment module where I must pass the data without decimals, only number. Examples:

  

10,00 = 1000

     

100,30 = 10030

     

1.000,00 = 100000

I searched for some function in% with format decimal places , but the tests I performed did not go as expected, could anyone help me with this?

    
asked by anonymous 16.11.2016 / 13:17

3 answers

1

In case, what you need is very simple, remove any value other than number:

$entrada = '100,30'; 

echo preg_replace('/[^0-9]+/','',$entrada);

Example in IDEONE

    
16.11.2016 / 15:58
2

Use the str_replace by placing what you are looking for in a array " and what changes in the particular case space-less quotes ( '' ):

<?php

$numero = "1.000,00";
$result = str_replace(['.',','],'', $numero);
echo $result;

Example Online Ideone

Reference:

Edit:

Really an answer already exists

    
16.11.2016 / 13:37
0

for comma use:

$numero = '100,30';

$SemVirgula  = str_replace(',', '', $numero );

to use point:

$numero = '100.30';

$SemVirgula  = str_replace('.', '', $numero );

For both use:

$numero = '2.100,30';

$SemVirgula  = str_replace(',', '', $numero );

$SemPonto  = str_replace('.', '', $SemVirgula );

Another way to remove semicolons:

$numero = '2.100,30';

$substituir = array(',', '.');

$substituidos = array('', '');

$NumFormatado = str_replace($substituir, $substituidos, $numero);
    
16.11.2016 / 13:33