I need to show a currency value in the format of 1K of equal to one thousand, or 1.1K, 1.2K, 1.9K etc, if its not an even thousands, otherwise if under a thousand, display normal 500, 100, 250 etc, using javascript to format the number?
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- How to fix IE ClearType + jQuery opacity problem i
- void before promise syntax
- jQuery add and remove delay
This post is quite old but I somehow reached to this post searching for something. SO to add my input Numeral js is the one stop solution now a days. It gives a large number of methods to help formatting the numbers
http://numeraljs.com/
A more generalized version:
Further improving Salman's Answer because it returns nFormatter(33000) as 33.0K
now nFormatter(33000) = 33K
!Number.isFinite
' K M G T P E Z Y'
to' K M'
if you want the max unit isM
Adding on the top answer, this will give 1k for 1000 instead of 1.0k