JS under the Arabic numerals per three-bit comma-delimited (such as: 15000000 conversion to 15,000,000) _javascript tips

Source: Internet
Author: User

Copy Code code as follows:

"15000000". Split (""). Reverse (). Join (""). Replace (/(\d{3})/g, "$"). Split (""). Reverse (). Join ("");
"115000000". Split (""). Reverse (). Join (""). Replace (/(\d{3}) (? =[^$])/g, "$"). Split (""). Reverse (). Join ("");

Copy Code code as follows:

var cutstr = function (str)
{
var newstr= new Array (str.length+ parseint (STR.LENGTH/3));
NEWSTR[NEWSTR.LENGTH-1]=STR[STR.LENGTH-1];
var currentindex=str.length-1;
for (var i = newstr.length-1;i >= 0;i--)
{
if ((newstr.length-i)%4==0)
{
Newstr[i]= ",";
}
Else
{
newstr[i]=str[currentindex--];
}
}
Return Newstr.join ("")
}
var num= "15000000";
Console.log (CUTSTR (num));
function Cutstr (str) {
var rmb= ';
var i2=0;
for (var i=str.length-1; i>=0; i--) {

if (i%3==0&&i!=0) {
Rmb+=str[i2]+ ', ';
}else{
RMB+=STR[I2];
}
i2++;
}
return RMB;
}
Console.log (CUTSTR (num));
function Cutstr (num) {
var AAA = num.tostring ();
var arr1 = Aaa.split ("");
var arr2 = [];
for (var i = 0; i < arr1.length;) {

for (j = 0; J < 3; J + +) {

Arr2.unshift (Arr1[i]);
i++;
if (j = = 2 && i < arr1.length) {
Arr2.unshift (",");
}
}
}

Alert (Arr2.join (""));
}
Cutstr (12345678);
' 1500000000000 '. Replace (/\b (? = (\d{3}) +$)/g, ', ')
function FormatNumber (value) {
Value = Value.tostring ();
if (value.length <= 3) {
return value;
} else {
Return FormatNumber (value.substr (0, value.length-3)) + ', ' + value.substr (value.length-3);
}
}
Console.log (FormatNumber (12345678))
var str = ' 123123211312.333123 '. Replace (/? = (?! ^)(?:\ D{3}) + (?: \.| $)) (\d{3} (\.\d+$)?) /g, ', $ ');
Console.log (str)

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.