"Notice: A non well formed numeric value encountered" PHP

"Notice: A non well formed numeric value encountered" PHP

计算结果出现以下错误。我看不出退出代码有任何问题。那么,为什么会出现此错误,我该如何解决?

// b2Cost = 19.020843;

return (float)number_format((float)str_replace(",", ".", $b2Cost), 2, ".", "");

错误:

Notice: A non well formed numeric value encountered 

尝试

return (float)number_format((float)str_replace(",", ".", (string) $b2Cost), 2, ".", "");

但是如果你只是想缩短浮动,看看https://www.php.net/manual/en/function.round.php