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
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/.