PHP: get number of decimal digits

前端 未结 18 2271
忘了有多久
忘了有多久 2020-11-28 09:25

Is there a straightforward way of determining the number of decimal places in a(n) integer/double value in PHP? (that is, without using explode)

18条回答
  •  春和景丽
    2020-11-28 10:21

    I used the following to determine whether a returned value has any decimals (actual decimal values, not just formatted to display decimals like 100.00):

    if($mynum - floor($mynum)>0) {has decimals;} else {no decimals;} 
    

提交回复
热议问题