Skip Navigation

[Resolved] Comma format

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

Problem:

The issue here here is that the user wanted to format the output from their number field with a comma for every thousand.

Solution:
This is not something that can be done natively with our Toolset plugins and as such you will need to use a little bit of custom code to format the numbers.

I've written a simple custom shortcode below to format the numbers for you.

// Add Shortcode
function wp_format_number( $atts ) {
 
    // Attributes
    $atts = shortcode_atts(
        array(
            'number' => '',
        ),
        $atts
    );
 
    return number_format($atts['number'],0,'.',',');
 
}
add_shortcode( 'wp_format_number', 'wp_format_number' );

Add it to your Toolset Custom Code section in Toolset->Settings->Custom Code and activate it.

Then you can simply use the shortcode like this [wp_format_number number='[wpv-items-count]']

Relevant Documentation:

This support ticket is created 3 years, 3 months 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
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 2 replies, has 2 voices.

Last updated by rajivG 3 years, 3 months ago.

Assisted by: Shane.

Author
Posts
#2139993

Hi,

I have a query, please.

May I know the way to get the output of the following numbers in comma format?

[wpv-items-count] of [wpv-found-count] results found

For example, in this way: 2,017 of 1,00,000 results found

Thank you.

Rajiv

#2140307

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Rajiv,

This is not something that can be done natively with our Toolset plugins and as such you will need to use a little bit of custom code to format the numbers.

I've written a simple custom shortcode below to format the numbers for you.

// Add Shortcode
function wp_format_number( $atts ) {

	// Attributes
	$atts = shortcode_atts(
		array(
			'number' => '',
		),
		$atts
	);

	return number_format($atts['number'],0,'.',',');

}
add_shortcode( 'wp_format_number', 'wp_format_number' );

Add it to your Toolset Custom Code section in Toolset->Settings->Custom Code and activate it.

Then you can simply use the shortcode like this [wp_format_number number='[wpv-items-count]']

Please let me know if this helps.
Thanks,
Shane

#2140367

It worked! Thank you, Shane for helping out. Appreciated.