Skip Navigation

[Resolved] Formatting a NUMERIC value in a View

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

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.

This topic contains 1 reply, has 2 voices.

Last updated by Beda 4 years, 8 months ago.

Author
Posts
#1541511

Hi,

I’m trying to format a NUMBER field to display with 2 decimals..

I’ve used an example from another ticket to create a shortcake and use it like this in a View:

<td>[format-gpa][types field="gpa"][/types][/format-gpa]</td>
<td>[format-gpa][types field="gpa-total"][/types][/format-gpa]</td>

This is the Shortcode code in functions.php:

// format GPA numbers nicely with 2 decimals
// function converts meta data which is stored as a string to a float
function format_gpa($atts) {
$num = $atts[“num”];
$float_value_of_var = floatval($num);

return number_format($float_value_of_var, 0, ‘.’);
}
add_shortcode(“format-gpa”, “format_gpa”);

But I get this on displaying the view:

hidden link

#1541683

It's not possible to output these fields in other formats than I explained here a few days ago:
https://toolset.com/forums/topic/how-do-i-format-numeric-field-data-in-a-content-template/

Unfortunately for such formatting features, you have to either use a single line and input your formats there, or, if you wish this in the Number field, then a feature request would be the right approach, so the Product Management can consider such feature.

The result you share in the link seems like the ShortCode is not executing, so it is not registered, or something is interfering with it.
But this is custom code, that we cannot fully assist in this forum, please see https://toolset.com/toolset-support-policy/

The Toolset ShortCode indeed works fine, I can see that it is the custom shortcode failing, which would require custom debug done on the ShortCode. We cannot do this, in the forum, but you could if required contact a contractor from here https://toolset.com/contractors/.