简体   繁体   中英

AngularJS format big numbers

I have a table with numbers, are really bigs, so I'm looking for something to format that numbers like $13b, $10m ...

Somebody has made this before and has something to do it? like a customized filter?

Thanks!

This helped me, helps you too.

var lazyround = function (num) {
var parts = num.split(",");
return parts.length > 1 ? (Math.round(parseInt(parts.join(""), 10) / Math.pow(1000, parts.length-1)) + " " + ["thousand", "million", "billion"][parts.length-2]) : parts[0];

};

there you have a working example in jsfiddle: http://jsfiddle.net/p8pfB/

为什么不只是将此数字保存为字符串?

var myBigNumbers = ['121394819394814818419391393901', ...]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM