Javascript-how can I use PHP or JS to display the number of readings in a friendly manner? For example, convert 1000 to 1 k and 10000 to 1 w.

Source: Internet
Author: User
The number above one thousand can be formatted as 1 K. For example, 1320 is converted to 13200 K or to. This plug-in has not been found for a long time on the Internet, which of the following experts can tell me where to find the plug-in or what the plug-in name is? Thank you ~

The number above one thousand can be formatted as 1 k
For example, 1320 is converted to 1.3 kb.
Or 13200 to 1.32 w


Results: I have been searching for this plug-in online for a long time, and I have not found this plug-in. Which of the following experts can tell me where to find it or what the plug-in name is? Thank you ~

Reply content:

The number above one thousand can be formatted as 1 k
For example, 1320 is converted to 1.3 kb.
Or 13200 to 1.32 w


Results: I have been searching for this plug-in online for a long time, and I have not found this plug-in. Which of the following experts can tell me where to find it or what the plug-in name is? Thank you ~

function test($num){    if($num < 1000) {       return $num;    } else if($num >=1000 && $num < 10000){       return round($num/1000,1).'k';    } else if ($num >= 10000) {       return round($num/10000,2).'w';    }}echo test(1320);


  = 10000) {        $num = round($num / 10000 * 100) / 100 .' W';    } elseif($num >= 1000) {        $num = round($num / 1000 * 100) / 100 . ' K';    } else {        $num = $num;    }    return $num;}echo num2tring(12300); //1.23 Wecho num2tring(1200); //1.2 Kecho num2tring(200); //200

In JavaScript, divide the number by 1000, and then use Math. floor to round down the result.
Math. floor (n/1000) + 'K' k
Php also has similar usage

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.