A better way to write large numbers - Daily JavaScript Tips #9

A better way to write large numbers - Daily JavaScript Tips #9

ยท

1 min read

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

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)

Copy this code and try once!


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

ย