首頁  >  文章  >  後端開發  >  php如何將float轉int?

php如何將float轉int?

Guanhui
Guanhui原創
2020-07-22 11:28:404749瀏覽

php如何將float轉int?

php如何將float轉int?

1、使用函數「intval」將float類型資料轉換為int型別;

$float = 15.222;
intval($float);

2、使用「settype()」將float型別資料設為int型別;

$float = 15.222;
settype($float, 'int');

3、在變數前面加上“ (int)”,將其強制轉換為int。

$float = 15.222;
(int) $float;

推薦教學:《PHP

以上是php如何將float轉int?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn