Get the length of numbers in typescript
To get the length of numbers in typescript, you can use the toString()
method with the length
property it will return the length of numbers.
// ✅ Get the length of numbers in typescript
let num: number = 493054;
num.toString().length;
// 👉️ 6
Today, I’m going to show you How do I get the length of numbers in typescript, as above mentioned here, I’m going to use thetoString()
method with the length
property to get the length of numbers;
Let’s start today’s tutorial how do you get the length of numbers in typescript?
First, I will take the sample number variable, then I will convert it to string and use the length
property, let’s console it.
// ✅ Get length of numbers in typescript
let num: number = 493054;
let lenOfNum: number = num.toString().length;
console.log(lenOfNum)
// 👉️ 6
I hope it helps you, All the best 👍.