Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

271
Vistas
Smarty php - how to replace 1000 to 1k, and so on

is there any way to replace this:

<div>{math equation="x - y" x={$n.total_rating} y={$n.total_ratings}}</div>

Where results is for example 1300 to receive this 1.3k, and so on...

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Try in libs\plugins\modifier.num_format.php

<?php
/**
 * Smarty plugin
 *
 * @package    Smarty
 * @subpackage PluginsModifier
 */

function smarty_modifier_num_format($string) {
  if($string>1000) {
  $x = round($string);
        $x_number_format = number_format($x);
        $x_array = explode(',', $x_number_format);
        $x_parts = array('k', 'm', 'b', 't');
        $x_count_parts = count($x_array) - 1;
        $x_display = $x;
        $x_display = $x_array[0] . ((int) $x_array[1][0] !== 0 ? '.' . $x_array[1][0] : '');
        $x_display .= $x_parts[$x_count_parts - 1];
        return $x_display;
  }
  return $string;
}

and in theme file

{assign var="mynubers" value="{math equation="x - y" x={$n.total_rating} y={$n.total_ratings}}"}
{if $mynubers > '1000'}{$mynubers|num_format}{else}{$mynubers}{/if}
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda