Not Solved How can I get this types of view format???
#1
Not Solved
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


Attached Files Thumbnail(s)
   
Reply
#2
Not Solved
There is no simple option.
It is necessary to modify PHP code adding new procedures to calculate number in thousands/millions.

[ExiTuS]
MyBB Forum + innovative full-responsive Theme
Live-Escape-Game-Forum
Reply
#3
Not Solved
@ExiTus
How can I achieve that, can you help me on that
Reply
#4
Not Solved
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>
Name's Waleed, I'm a graphic and web design (2015) graduate from Canada. Self-employed and lending my design skills to the MyBB community.
Reply
#5
Not Solved
Cool it work
Reply
#6
Not Solved
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.
[MyBB 1.8 mods] - Offer me a coffee
Do not ask me help through PM or Discord
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)