Hi all
some time ago you helped me creating a snippet that allowed me to convert currency values from US to EU format. This is the function:
function format_my_number($atts)
{
$atts = shortcode_atts(
array(
'num' => '',
'sym' => '',
),
$atts
);
$num = $atts['num'];
return number_format($num, 0, ',', '.').' '.$atts['sym'];
}
add_shortcode('format-currency', 'format_my_number');
I was recently required to move my site to PHP 8 and I now get the fatal error attached from the function (that still works fine on frontend, but it fails when editing the page).
Could you please help me to fix the issue ?
thanks
Regards
Nicola
Minesh
Supporter
Languages:
English (English )
Timezone:
Asia/Kolkata (GMT+05:30)
Hello. Thank you for contacting the Toolset support.
What if you try to use the following function. It seems with PHP 8 it has a strict type casting for variables.
Could you please try to use the following code and check if that help you to resolve your issue:
function format_my_number($atts)
{
$atts = shortcode_atts(
array(
'num' => '0',
'sym' => '',
),
$atts
);
$num = $atts['num'];
$num = floatval($num);
return number_format($num, 0, ',', '.').' '.$atts['sym'];
}
add_shortcode('format-currency', 'format_my_number');
My issue is resolved now. Thank you!