Skip Navigation

[Resolved] How to display a numeric field divided by 100 ? continue…

This thread is resolved. Here is a description of the problem and solution.

Problem:
How to display custom numeric field divided by 100.

Solution:
To divide custom field value by 100, you need to add custom shortcode to your current theme's functions.php file:

add_shortcode('format_length', 'func_format_length');
function func_format_length( $atts,$content ) {
     
$value = wpv_do_shortcode(trim($content));
$value = $value / 100;
return number_format($value, 2);
}

Use the shortcode as follows:

[format_length] [types field="lengte" output="raw"][/types][/format_length]

Where:
Replace "lengte" with your types field name.

Relevant Documentation:

This support ticket is created 8 years, 1 month ago. 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.

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)

Tagged: 

This topic contains 2 replies, has 2 voices.

Last updated by mcjS 8 years, 1 month ago.

Assisted by: Minesh.

Author
Posts
#373222

I am trying to: To display a numeric field divided by 100

I visited this URL: https://toolset.com/forums/topic/how-to-display-a-numeric-field-divided-by-100/

I expected to see: 11.90 (the field value is 1190)

Instead, I got: 0.0119 on my screen in a view.

This is my code in functions.php

function format_length( $atts ) {
extract( shortcode_atts( array(
'meter' => '0'), $atts) );
return $meter = number_format($meter, 2, ',', '.') / 100;
}
add_shortcode('format_length', 'format_length');

&

Third-party shortcode arguments

[format_length]

&

Lengte: [format_length meter=[types field="lengte" format="FIELD_VALUE"][/types]][/format_length]
(in the template of the view)

#373265

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Could you please try following modified shortcode:

Add following shortcode to your functions.php file.

add_shortcode('format_length', 'func_format_length');
function func_format_length( $atts,$content ) {
	
$value = wpv_do_shortcode(trim($content));
$value = $value / 100;
return number_format($value, 2);
}

Use the shortcode as follows:
Lengte: [format_length] [types field="lengte" output="raw"][/types][/format_length]

#373313

it works, tnx

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.