简体   繁体   中英

How to format big numbers in JavaScript?

I have the following big number: 2.9364136545300044e+24 I heed to format this value to 2,936,413.65 value

How could I do it of are there any libraries to make it?

You can use Intl.NumberFormat.prototype.format , String.prototype.slice() , String.prototype.concat()

 var number = 2.9364136545300044e+24; var n = new Intl.NumberFormat().format(number); var res = n.slice(0, 9).concat(".").concat(n.slice(10, 12)); console.log(res); 

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