2013-03-20 8 views
7

Molti altri sembrano aver avuto questo problema, ma in genere associati a un tipo di dati MySQL.Conversione di una stringa in un intero restituisce 2147483647

Sto cercando di convertire una stringa in un intero come questo:

$adGroupId = '5947939396'; 
$adGroupId = intval($adGroupId) 

Tuttavia l'intero restituito è 2147483647, indipendentemente dalla stringa di input.

+7

perché questo è il valore massimo int. usa float ... –

+1

possibile duplicato di [PHP: intval() equivalente per i numeri> = 2147483647] (http://stackoverflow.com/questions/990406/php-intval-equivalent-for-numbers-2147483647) –

+1

^^ Valore int massimo per sistemi a 32 bit. –

risposta

13

Questo numero è troppo grande per entrare in un tipo di dati intero (il valore massimo intero è 2147483647 come visto sopra). Converting it to a float instead will work:

$adGroupId = '5947939396'; 
$adGroupId = floatval($adGroupId) 
+0

Grazie, anche se floatval restituisce la stringa come un gettype double, non intero? – Boomfelled

+2

@Boomfelled Questo è il punto. Il tuo numero (acqua) è troppo grande per un intero (bucket), quindi usare floatval è come usare un bucket più grande. Se alla fine tenterai di inserire questo numero in un campo intero mysql, avrai bisogno di cambiare anche il tipo di quel campo o avrai un problema simile. – Mansfield

+0

Grande, grazie molte. – Boomfelled

4

Sta succedendo perché 2147483647 è il valore intero massimo. È possibile utilizzare floatval

$adGroupId = '5947939396'; 
$adGroupId = floatval($adGroupId); 
echo $adGroupId; 
Problemi correlati