Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Number converted in 1e+30

Tags:

javascript

How to convert 1e+30 to 1000000000000000000000000000000

I want number as it is entered by User do not convert like 1e+30.

How can achieve this? Is there any way to display actual digits after parse it to float or int?

like image 354
Sadikhasan Avatar asked Dec 15 '22 17:12

Sadikhasan


2 Answers

The core library doesn't give you any support for numbers that don't fit into the native number type, so you'll probably want to use a third party library to help you with large decimals.

For example, https://mikemcl.github.io/decimal.js/

new Decimal('1e+30').toFixed()
// "1000000000000000000000000000000"
like image 117
Chris Martin Avatar answered Feb 01 '23 22:02

Chris Martin


You may use toLocaleString

(1000000000000000000000000000000).toLocaleString("en-US", { useGrouping: false })
like image 31
user4344980 Avatar answered Feb 02 '23 00:02

user4344980