Removing all decimals in PHP

前端 未结 10 1996
囚心锁ツ
囚心锁ツ 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:49

    you can use echo (int) 252.587254564;

    0 讨论(0)
  • 2020-12-16 12:53

    In MySQL you can use:

    select floor(field)
    

    or in PHP you can use:

    floor($value);
    
    0 讨论(0)
  • 2020-12-16 12:54

    You can do it in PHP:

    round($val, 0);
    

    or in your MYSQL statement:

    select round(foo_value, 0) value from foo
    
    0 讨论(0)
  • 2020-12-16 12:54

    You can just cast it to an int:

    $new = (int)$old;
    
    0 讨论(0)
提交回复
热议问题