Skip Navigation

[Résolu] Function for formating money causes warning

Ce fil est résolu. Voici une description du problème et la solution proposée.

Problem:
Display numeric custom field in European format.

Solution:
Add this code in your theme’s or child theme’s functions.php file:

function format_money( $atts ) {
extract( shortcode_atts( array(
'price' => '0'), $atts) );
return $price = number_format($price, 0, ',', ' ');
}
add_shortcode('format_money', 'format_money');

Relevant Documentation:
you like to use integer or float value:
https://stackoverflow.com/questions/27967044/warning-number-format-expects-parameter-1-to-be-double-string-given-in#answer-27968675

This support ticket is created Il y a 7 années et 1 mois. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Aucun de nos assistants n'est disponible aujourd'hui sur le forum Jeu d'outils. Veuillez créer un ticket, et nous nous le traiterons dès notre prochaine connexion. Merci de votre compréhension.

Sun Mon Tue Wed Thu Fri Sat
- 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 -
- 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

Ce sujet contient 2 réponses, a 2 voix.

Dernière mise à jour par toolset-dave Il y a 7 années et 1 mois.

Assisté par: Noman.

Auteur
Publications
#583660

Hi,

I use function https://toolset.com/forums/topic/displaying-price-in-european-format/

function format_money( $atts ) {
extract( shortcode_atts( array(
'price' => '0'), $atts) );
return $price = number_format($price, 0, ',', ' ');
}
add_shortcode('format_money', 'format_money');

It works fine, but causes warning in WordPress backend:

Warning: number_format() expects parameter 1 to be float, string given in /.../functions.php on line 204

How to get rid of it?

#584100

Noman
Supporter

Les langues: Anglais (English )

Fuseau horaire: Asia/Karachi (GMT+05:00)

Hi Dave,

Thank you for getting in touch with us. I tested this code and I am not getting the error you have mentioned. Which type of value you are using -- integer or float or some other format?

You can modify the code as per your need like explained here -- for example if you like to use float value:
https://stackoverflow.com/questions/27967044/warning-number-format-expects-parameter-1-to-be-double-string-given-in#answer-27968675

Please let me know, Thank you

#584622

Thanks for the link, it solved my problem.