Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8738945
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:50:28+00:00 2026-06-13T10:50:28+00:00

Edit: Function below now does the abbreviation correctly, implemented @Asad ‘s solution Hi I

  • 0

Edit: Function below now does the abbreviation correctly, implemented @Asad ‘s solution

Hi I am currently working on a like button, I’ve got all the base functionality working nicely however I have started the number abbreviation code and hit a wall as I can’t figure out how to make the abbreviation more precise.

I have a number, e.g. 1000, 1230, 1500, 154000, 1500000, 1000000

And I want to format them with an abbreviation. i.e.

if it’s a thousand, then 1k, 1.1k, 2k, 10k, 10.5k etc…

and so on for the tens, hundreds thousands and millions, etc…

At the moment I have the following function but it’s not specific enough:

function abreviateTotalCount($value) 
{

    $abbreviations = array(12 => 'T', 9 => 'B', 6 => 'M', 3 => 'K', 0 => '');

    foreach($abbreviations as $exponent => $abbreviation) 
    {

        if($value >= pow(10, $exponent)) 
        {

            return round(floatval($value / pow(10, $exponent))).$abbreviation;

        }

    }

}

Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T10:50:29+00:00Added an answer on June 13, 2026 at 10:50 am

    If you want to keep the decimal places, use floatval instead of intval:

    return round(floatval($value / pow(10, $exponent)),1).$abbreviation;
    

    gets the float representation and rounds to 1 decimal place.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to use ajax like below; jquery code: $(a.generate).click(function(){ $.ajax({ data: {tag:
EDIT: It now works, but does not load if the user does not allow
I'm trying to add an edit function to my web app but I'm having
I have an HTML table where I'm building an edit function to change a
I register the following function //EDIT: updated $("#id").on("change", function() { alert('xxx'); }); In my
I tried the following: $.load(Views/chatBox.html).appendTo('body') Console Output: TypeError: $.load is not a function EDIT
I have this function to edit all fields that come from the form and
EDIT : Per Slaks $j('#banner-content img').each(function() { var link = $j('#page-tabs li a.' +
I have following function in one Activity public void AppExit() { Editor edit =
I have a function that allows users to edit a row in a table

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.