Skip Navigation

[Resolved] number_format shortcode strips values

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

Problem:

Display numeric values with comma separators for thousands, and two decimal places

Solution:

It needs custom codes, see details here:

https://toolset.com/forums/topic/number_format-shortcode-strips-values/#post-1137414

Relevant Documentation:

This support ticket is created 6 years 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Hong_Kong (GMT+08:00)

Tagged: 

This topic contains 3 replies, has 2 voices.

Last updated by Luo Yang 6 years ago.

Assisted by: Luo Yang.

Author
Posts
#1136850

I am trying to:

Display numeric values with comma separators for thousands, and two decimal places

Link to a page where the issue can be seen:

hidden link

I expected to see:

HARBOR GRAIN- LONG BEACH should display a value of $1,491.00

PTI OAKLAND should display a value of $68,203.00

Instead, I got:

both warehouses display $0.00

I created a shortcode to format the value field being displayed in the Inventory by Warehouse view.

function yls_format_money( $atts ) {
	extract( shortcode_atts( array(
	'warehouse-value' => '0'), $atts) );
	return $value = number_format((float)$value, 2);
}
add_shortcode('format_money', 'yls_format_money');

shortcode used in the view

<td>$[format_money value=[wpv-post-field name="warehouse-value"][/format_money]</td>

I've tested without converting to a float and I get warnings and no display output, I've also tested with (int) to the same result. I've searched through the support threads and found this: https://toolset.com/forums/topic/need-to-display-numeric-custom-field-in-european-decimal-format/#post-303215

Looks like in the last post another user had the same issue, please take a look and let me know what I'm doing incorrectly.

#1137414

Hi,

Thanks for the details, the thread you mentioned above is a for another custom field which is not created by Types plugin, in your case, the custom field "warehouse-value" is created by Types plugin, so things are different.

I have done below modification in your website:
1) Modify the PHP codes as below:

//This function creates a short code to format money
function yls_format_money( $atts, $content ) {
	$content = do_shortcode($content);
	return $value = number_format((float)$content, 2);
}
add_shortcode('format_money', 'yls_format_money');

2) Edit the view "Inventory Per Warehouse", change the shortcode as below:

$[format_money][types field='warehouse-value' output='raw'][/types][/format_money]

As you can see, you can use custom shortcode [format_money] to wrap the Types shortcode.

Please test again check if it is fixed, thanks

#1137587

That resolved the issue, thanks again!

#1137870

You are welcome