PHP String to Float

前端 未结 8 1288
别跟我提以往
别跟我提以往 2020-11-28 05:37

I am not familiar with PHP at all and had a quick question.

I have 2 variables pricePerUnit and InvoicedUnits. Here\'s the code that is set

8条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-28 05:44

    If you need to handle values that cannot be converted separately, you can use this method:

    try {
        $valueToUse = trim($stringThatMightBeNumeric) + 0;
    } catch (\Throwable $th) {
        // bail here if you need to
    }
    

提交回复
热议问题