How to convert long number to K M B |
How to convert long number to K M B |
The_webmaster |
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
|
pandy |
Sep 26 2021, 01:45 PM
Post
#2
|
🌟Computer says no🌟 Group: WDG Moderators Posts: 20,730 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.
|
The_webmaster |
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 ?
|
The_webmaster |
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!
|
pandy |
Sep 27 2021, 11:27 AM
Post
#5
|
🌟Computer says no🌟 Group: WDG Moderators Posts: 20,730 Joined: 9-August 06 Member No.: 6 |
Yes, I realized later I missed that bit. Sorry.
|
Lo-Fi Version | Time is now: 19th April 2024 - 10:14 PM |