Skip Navigation

[Resolved] I have a problem with displaying numbers with decimal

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.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 2 replies, has 2 voices.

Last updated by Minesh 3 months, 2 weeks ago.

Assisted by: Minesh.

Author
Posts
#2711854
decimal.png

Hi,

Since I have a Dutch website, I need to use commas for decimal points in number fields. For example, I enter 1,8, but I get a warning: Please enter numeric data. When I change the number to 1.8, it displays as this on the frontend. I need to be able to use commas for decimals. How can I make this work on the frontend?

hidden link

I already have some code in the functions.php file for the second part, as shown in green below "Wat zit er allemaal in Aardappel". Could you please modify the code to make it work site-wide?

function custom_number_format_shortcode($atts) {
$atts = shortcode_atts(array(
'field' => '',
), $atts);

$post_id = get_the_ID();
$value = get_post_meta($post_id, $atts['field'], true);

if (is_numeric($value)) {
return number_format((float)$value, 2, ',', '.');
}

return $value; // Return original value if not numeric
}
add_shortcode('custom_number', 'custom_number_format_shortcode');

#2711863

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Can you please share admin access details and let me check what could be the possible solution for this.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#2711896

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I can see you are using the following template to display the single post link you shared:
- hidden link

with that I can see you are displaying the content as given under:

Per 100 gram
<ul>
 	<li>Zuur-base: {!{types field='zuurgraad'}!}{!{/types}!}</li>
 	<li>Kilojoule: {!{types field='kilojoule' format='FIELD_VALUE'}!}{!{/types}!} Kj</li>
 	<li>Calorieën: {!{types field='calorieen-100-gram' format='FIELD_VALUE'}!}{!{/types}!} kcal</li>
 	<li>Koolhydraten: {!{types field='koolhydraten' format='FIELD_VALUE'}!}{!{/types}!} gram</li>
 	<li>Eiwit: {!{types field='eiwit-totaal' format='FIELD_VALUE'}!}{!{/types}!} gram</li>
 	<li>Voedingsvezels: [custom_number field="wpcf-voedingsvezels"] gram</li>
 	<li>Vetten: {!{types field='vet-totaal' format='FIELD_VALUE'}!}{!{/types}!} gram</li>
 	<li>Water: {!{types field='water-totaal' format='FIELD_VALUE'}!}{!{/types}!} gram</li>
 	<li>Histaminetrigger: {!{types field='histaminetrigger'}!}{!{/types}!}</li>
 	<li>Dit voedingsmiddel is {!{types field='darmflora'}!}{!{/types}!}</li>
 	<li>{!{wpv-view name='bronnen'}!}</li>
</ul>

Currently - you have this line of code that displays the number field with dot.

{!{types field='voedingsvezels' format='FIELD_VALUE'}!}{!{/types}!}

To whatever field you want to display comma, you need to replace the code line as given under:

[custom_number field="wpcf-voedingsvezels"] 

Can you please confrim - it works as expected now:
- hidden link

#2711972

super! thank you Minesh