MyBB Community Forums

Full Version: How can I get this types of view format???
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Help needed Bosses in the house

How can I made my showthread view to be in this format e.g 31k 

Instead of that long 31573 

How can I get the format to make the view be in 31k, when it reach million it should be 31M etc

How can I get that please

Check below image for what am saying, I wanna get rid of that view format
There is no simple option.
It is necessary to modify PHP code adding new procedures to calculate number in thousands/millions.

[ExiTuS]
@ExiTus
How can I achieve that, can you help me on that
This script will abbreviate/shorten the number when applied to the views on your showthread template.
https://stackoverflow.com/questions/1815...-represent

<script>
function abbreviate(number, maxPlaces, forcePlaces, forceLetter) {
  number = Number(number)
  forceLetter = forceLetter || false
  if(forceLetter !== false) {
    return annotate(number, maxPlaces, forcePlaces, forceLetter)
  }
  var abbr
  if(number >= 1e12) {
    abbr = 'T'
  }
  else if(number >= 1e9) {
    abbr = 'B'
  }
  else if(number >= 1e6) {
    abbr = 'M'
  }
  else if(number >= 1e3) {
    abbr = 'K'
  }
  else {
    abbr = ''
  }
  return annotate(number, maxPlaces, forcePlaces, abbr)
}

function annotate(number, maxPlaces, forcePlaces, abbr) {
  // set places to false to not round
  var rounded = 0
  switch(abbr) {
    case 'T':
      rounded = number / 1e12
      break
    case 'B':
      rounded = number / 1e9
      break
    case 'M':
      rounded = number / 1e6
      break
    case 'K':
      rounded = number / 1e3
      break
    case '':
      rounded = number
      break
  }
  if(maxPlaces !== false) {
    var test = new RegExp('\\.\\d{' + (maxPlaces + 1) + ',}$')
    if(test.test(('' + rounded))) {
      rounded = rounded.toFixed(maxPlaces)
    }
  }
  if(forcePlaces !== false) {
    rounded = Number(rounded).toFixed(forcePlaces)
  }
  return rounded + abbr
}
</script>
Cool it work
Normal: there is no call of the abbreviate function. And using JS to modify this kind of stats seems strange for me.
imho, the best might be to create a plugin which will replace the numerical value with the abbreviated one.