- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Expressing numbers in expanded form - JavaScript
Suppose we are given a number 124 and are required to write a function that takes this number as input and returns its expanded form as a string.
The expanded form of 124 is −
'100+20+4'
Example
Following is the code −
const num = 125; const expandedForm = num => { const numStr = String(num); let res = ''; for(let i = 0; i < numStr.length; i++){ const placeValue = +(numStr[i]) * Math.pow(10, (numStr.length - 1 - i)); if(numStr.length - i > 1){ res += `${placeValue}+` }else{ res += placeValue; }; }; return res; }; console.log(expandedForm(num));
Output
Following is the output in the console −
100+20+5
- Related Articles
- Returning the expanded form of a number in JavaScript
- Expanded form of 6,72,789
- Expanded form of 23434 is____.
- Write the following decimal numbers in the expanded form:$(i)$. 20.03$(ii)$. 2.03$(iii)$. 200.03 $(iv)$. 2.034
- Write the expanded form of the number 4,18,395.
- Determining whether numbers form additive sequence in JavaScript
- Write the following in the expanded form:( (a+2 b+c)^{2} )
- Write the following in the expanded form:( (-3 x+y+z)^{2} )
- Write the following in the expanded form:( (2+x-2 y)^{2} )
- Write the following in the expanded form:( (2 x-y+z)^{2} )
- Write the following in the expanded form:( (2 a-3 b-c)^{2} )
- Write the following in the expanded form:( (m+2 n-5 p)^{2} )
- Write the following in the expanded form:( (x+2 y+4 z)^{2} )
- Write the following in the expanded form:( (a^{2}+b^{2}+c^{2})^{2} )
- Write the following in the expanded form:( (a b+b c+c a)^{2} )

Advertisements