Removing all decimals in PHP

前端 未结 10 2134
囚心锁ツ
囚心锁ツ 2020-12-16 12:27

get this from my database:

252.587254564

Well i wanna remove the .587254564 and keep the 252, how can i do that?

10条回答
  •  孤街浪徒
    2020-12-16 12:27

    As Tricker mentioned you can round the value down or you can just cast it to int like so:

    $variable = 252.587254564; // this is of type double
    $variable = (int)$variable; // this will cast the type from double to int causing it to strip the floating point.
    

提交回复
热议问题