The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> How to convert long number to K M B
The_webmaster
post Sep 26 2021, 09:06 AM
Post #1


Member
***

Group: Members
Posts: 40
Joined: 5-February 21
Member No.: 27,773



Hi, please I want to convert long number to K,M or B. Example 1200 - 1.2k, 120000 - 1.2M. Can anyone help ? Thanks in advance
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post Sep 26 2021, 01:45 PM
Post #2


🌟Computer says no🌟
********

Group: WDG Moderators
Posts: 20,716
Joined: 9-August 06
Member No.: 6



Check if the number is less than 1000. If it is set your variable to the number. If not check if it's less than 1000000. If it is, divide with 1000 and set your variable to that + K. If that doesn't fit the bill, check if the number is less than 1000000000. If it is divide with 1000000 and set your variable to that + M. Lastly divide with 1000000000 and set your variable to that + B.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
The_webmaster
post Sep 27 2021, 04:42 AM
Post #3


Member
***

Group: Members
Posts: 40
Joined: 5-February 21
Member No.: 27,773



Yes i can divide it as you wrote but when i do it that way it causes some problem. Example: when the is 1550 and divided with 1000 it shows 1.55K but i want it to show like this 1.5K. Can you help me solve that ?
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
The_webmaster
post Sep 27 2021, 10:08 AM
Post #4


Member
***

Group: Members
Posts: 40
Joined: 5-February 21
Member No.: 27,773



Thanks Pandy, I divided as you wrote and set the visible numbers with toFixed() and that worked great. Thanks very much!
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post Sep 27 2021, 11:27 AM
Post #5


🌟Computer says no🌟
********

Group: WDG Moderators
Posts: 20,716
Joined: 9-August 06
Member No.: 6



Yes, I realized later I missed that bit. Sorry.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
2 User(s) are reading this topic (2 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 19th March 2024 - 02:38 AM