DEV Community

Cover image for Better way to store large number - Daily JavaScript Tips #9
Dhairya Shah
Dhairya Shah

Posted on • Originally published at codewithsnowbit.hashnode.dev

Better way to store large number - Daily JavaScript Tips #9

Hello Folks ๐Ÿ‘‹

What's up friends, this is SnowBit here. I am a passionate self-taught young developer having the intention to become a successful developer.

Today, I am here with an amazing topic about numbers ๐Ÿ’ฏ

So let's get started ๐Ÿš€,

Do you think it is a good idea to write lots of zeros for a billion or trillion?

const billion = 1000000000
const trillion = 1000000000000
Enter fullscreen mode Exit fullscreen mode

And the answer is a big NO! this way is only efficient for hundreds and thousands not for the big number like this. You can write like this but in the end, it becomes tedious and hard to read.

So, I have a proper solution for it and you will be amazed

const billion = 1e9
console.log("Billion " + billion)
const trillion = 1e12
console.log("Trillion " + trillion)
Enter fullscreen mode Exit fullscreen mode

Copy this code and try once!


Thank you for reading, have a nice day!
Your appreciation is my motivation ๐Ÿ˜Š

Top comments (0)