我在 inc.library.php 中遇到一些错误,什么是 number_format() 期望参数 1 为双精度?

i have got some error in inc.library.php, what is a number_format() expects parameter 1 to be double?

你好,我在 inc.library.php

中有一些错误

什么是 number_format() 期望参数 1 为双精度?

Warning: number_format() expects parameter 1 to be double, string given in /Applications/XAMPP/xamppfiles/htdocs/tes/library/inc.library.php on line 46

Warning: number_format() expects parameter 1 to be double, string given in /Applications/XAMPP/xamppfiles/htdocs/tes/library/inc.library.php on line 46

我在浏览器中有 2 个警告

此代码在 inc.library.php

function format_angka($angka) {
    $hasil =  number_format($angka,0, ",",".");
    return $hasil;
}

format_number 期望第一个参数是数字,而不是字符串。要将带小数点的数字字符串转换为数字,您可以使用函数 floatval(numberic_string).

 function format_angka($angka) {
    $hasil =  number_format(floatval($angka),0, ",",".");
    return $hasil;
}