Skip Navigation

[Resuelto] Formatting a NUMERIC value in a View

This support ticket is created hace 4 años, 9 meses. 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.

Hoy no hay técnicos de soporte disponibles en el foro Juego de herramientas. Siéntase libre de enviar sus tiques y les daremos trámite tan pronto como estemos disponibles en línea. Gracias por su comprensión.

Este tema contiene 1 respuesta, tiene 2 mensajes.

Última actualización por Beda hace 4 años, 9 meses.

Autor
Mensajes
#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:

enlace oculto

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