Transform large integer values into an array consisting of individual digits

I'm attempting to store the individual digits of a large integer in an array by converting it to a string first and then using the 'split()' method. However, it seems that in JavaScript, this method only works for integers up to 15 digits. For numbers larger than that, I'm getting exponential notation like '2.1321321381211322e+27' which cannot be directly stored in an array by first converting it to a string and splitting it. Instead, it appears as:

2 . 6 5 2 5 2 8 5 9 8 1 2 1 9 1 0 3 e + 3 2

Does anyone know how to handle large numbers in this situation?

Here is my code:

const myNum = 2132132138121132132145463636;
let myNumArray = ((myNum.toString()).split(''));
console.log(myNumArray);    //2 . 6 5 2 5 2 8 5 9 8 1 2 1 9 1 0 3 e + 3 2

Answer №1

For precise calculations, consider using the BigInt method:

const calculateNum = 2021n * 23n ** 7n;
let numArray = calculateNum.toString().split('');
console.log(numArray);

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Ensuring Stringency in JQuery's '$' Selector

I have a specific data attribute within the div element that is displayed in the HTML. <div my-custom-attrib="1".../> <div my-custom-sttrib="2"...> Now, in JQuery, I am attempting to filter between the div elements based on the value of the c ...

Backbone.js: Navigating the Default Path Issue

I've embarked on creating my very first BB app. Progress is decent, but I've hit a roadblock. My router implementation appears as follows: var PlayersAppRouter = Backbone.Router.extend({ routes: { '': 'index', ...

Error: Mongoose failed to cast DBrefs value to ObjectId

I am facing an issue with my Team Schema and Match Schema setup. I want the home/away teams in the Match Schema to refer to the Team object. However, I am encountering an error while trying to save the Team. I suspect there might be an issue with the Schem ...

Managing Jawbone API OAuth access tokens using node.js (express and passport)

Is there anyone who has successfully completed the Jawbone's OAuth2.0 authentication process for their REST API? I am facing difficulty in understanding how to access and send the authorization_code in order to obtain the access_token as mentioned in ...

Angular.js has encountered an error due to exceeding the maximum call stack size

Hello everyone! I attempted to create recursion in order to extend my $routeProvider in Angular.js with the following code: var pages = { 'home': { 'url': '/', 'partialName': 'index', ...

Stripping quotation marks from CSV information using Javascript

After performing a fetch request using JavaScript, I have converted JSON data into CSV format. datetime","open","high","low","close","volume" "2020-01-28","312.48999","318.39999","312.19000","317.69000","31027981" "2020-01-27","309.89999","311.76001","30 ...

Switching CSS styles with ng-click

Is there a way to toggle a CSS style based on an ng-click event? When the user clicks the ng-click element for the first time, the style is applied. However, when they click the ng-click element for the second time, the CSS does not change as expected to ...

populate a data list with information sourced in Angular 8

I am looking to populate this model oldDataSource: Array<any> = []; with the values from the datasource. This is the code I have tried: ngOnInit(): void { this.dataSourceInit(); } dataSourceInit(): void { this.dataSource = new DefaultScore ...

The error message "confirm is not a function" occurs when using the link_to function

I'm having trouble implementing a confirm dialogue box on a button, as it's not working and throwing an error: Here is my code snippet: <%= link_to restaurant_survey_path(@restaurant, id: @survey.id), data: { confirm: 'Are you sure?&apo ...

MongoDB failing to store model information

As I dive into practicing with APIs to hone my skills in creating models and routes, I find myself stuck on getting my initial route to successfully save data to my MongoDB database. When testing with Postman, I encounter the following error: { "message" ...

Update the style class of an <img> element using AJAX

My success with AJAX enables PHP execution upon image click. However, I seek a real-time visual representation without page reload. Thus, I aim to alter <img> tag classes on click. Presently, my image tag resembles something like <img title="< ...

After implementing two hooks with null properties, the code fails to execute

Recently, I encountered an issue with this section of the code after upgrading react scripts from version 2.0 to 5.0. const { user, dispatch } = useContext(AuthContext); const { data } = useFetch(`/contracts/${user.contractType}`); if (!user) { ...

I am sometimes experiencing issues with activating ajax code using Bootstrap 3 modal

I'm stumped trying to find a solution for this issue. Currently, I am utilizing the bootstrap modal to retrieve ajax content from a specified URL. To prevent content overlap, I am using $.removeData() when reloading the content. The problem arises w ...

Storing information in an array with automatic ID generation_incrementing

Here is an array in a specific format, however, there is no "ID" field available when the form is submitted. The requirement is to have an auto-generated ID assigned and saved in a JSON Array upon user submission of the form. With each form submission, t ...

Choose a selection in ExtJS by finding matching attributes

Is there a convenient method to choose an item in an Ext.tree.Panel by matching it with an item based on the same attribute in an Ext.grid.Panel? For example, using something like: tree_dir.getSelectionModel().select(grid_file.getSelectionModel().getSelect ...

Searching for a name in JSON or array data using jQuery can be accomplished by utilizing various methods and functions available

Having trouble searching data from an array in jQuery. When I input Wayfarer as the value for the src_keyword variable, it returns relevant data. PROBLEM The issue arises when I input Wayfarer Bag as the value for the src_keyword variable. It returns em ...

Using PHP Escape Functions in JavaScript

Can anyone help me with displaying item descriptions retrieved from a database query? Here is the code snippet that should display the description along with other details... <?php $type = "item"; $limit = 16; $preparedStatement = $SQL->prepare(& ...

Sending an array to another file upon button click event in a React application

Hey everyone, I'm currently getting started with React. I have this interesting situation where I need to handle an array of IDs that are obtained from selected checkboxes. My goal is to pass this array to another file called Employee.js when a button ...

Utilize the v-for second argument in VueJS 2 to showcase the index and index+1

For a VueJS 2 project, I am tasked with enhancing the display of the first and second elements in an array by making them stand out from the rest. To achieve this, I am utilizing the v-for syntax to iterate over a child component within a parent component. ...

What is the best way to retrieve state from a selector after refreshing the page?

In my React JS boilerplate code, I have a container component that retrieves data (such as a list of schools) using sagas into a reducer. The state set by the reducer is then read by a selector function on the render page to display to the user. Sample ...