On Sep 26, 6:50*pm, Sunny <sunnyluth...@gmail.comwrote:
Is there a way in Javascript to abbreviate currency.
Like if it is $1000 then it convert it into 1K.
To answer your question : Yes, there is; in fact, there are many.
A single example is inadequate to discriminate between possible
requirements.
One can only have $1000 in JavaScript if it is a String. In any
normal situation, one should start with the calculated Number.
But consider
S = "$1000000000"
S = S.replace(/(0+)$/, function(a, s) { var L = s.length
return ['','0','00'][L%3] + ['','K','M','G','T','P','E'][(L/3)|0]})
noting that each required member of set of inserted characters could
instead be obtained from a single String, using respectively substring
and charAt.
--
(c) John Stockton, near London, UK. Posting with Google.
Mail: J.R.""""""""@physics.org or (better) via Home Page at
Web: <URL:http://www.merlyn.demon.co.uk/>
FAQish topics, acronyms, links, etc.; Date, Delphi, JavaScript, ....|