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.
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
That resolved the issue, thanks again!