Azhimy Fzn
Azhimy Fzn

Reputation: 53

abs(): Argument #1 ($num) must be of type int|float, string given

I want to preview pdf, but not open after updated to php 8 and some package update.
This code notif from laravel

function konversi($x)

    {

        $x = abs($x);

        $angka = array("", "Satu", "Dua", "Tiga", "Empat", "Lima", "Enam", "Tujuh", "Delapan",   "Sembilan", "Sepuluh", "Sebelas");

        $temp = "";

 
> if ($x < 12) {// Notif from laravel in this line


            $temp = " " . $angka[$x];

        } else if ($x < 20) {

            $temp = konversi($x - 10) . " Belas";

        } else if ($x < 100) {

            $temp = konversi($x / 10) . " Puluh" . konversi($x % 10);

        } else if ($x < 200) {

            $temp = " Seratus" . konversi($x - 100);

        } else if ($x < 1000) {

            $temp = konversi($x / 100) . " Ratus" . konversi($x % 100);

        } else if ($x < 2000) {

            $temp = " Seribu" . konversi($x - 1000);

        } else if ($x < 1000000) {

            $temp = konversi($x / 1000) . " Ribu" . konversi($x % 1000);

        } else if ($x < 1000000000) {

            $temp = konversi($x / 1000000) . " Juta" . konversi($x % 1000000);

And this notif preview, Type Error

abs(): Argument #1 ($num) must be of type int|float, string given (View: C:\Users\Fauzan Azhim\Downloads\sci-tkdn-fixing_laporan\sci-tkdn-fixing_laporan\resources\views\laporan\cetak_permen_1.blade.php)

Upvotes: 3

Views: 19164

Answers (1)

Maik Lowrey
Maik Lowrey

Reputation: 17556

abs(): Argument #1 ($num) must be of type int|float, string given (View: C:\Users\Fauzan Azhim\Downloads\sci-tkdn-fixing_laporan\sci-tkdn-fixing_laporan\resources\views\laporan\cetak_permen_1.blade.php)

  1. The error comes from your blade file.
  2. change in this blade file abs($num) to abs((int) $num)
  3. Try again.

Upvotes: 5

Related Questions