Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

268
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!