JavaScript: Convert a float-point arithmetic to the Decimal mark form and It will make a comma separated string from a number
JavaScript: Exercise-125 with Solution
Write a JavaScript program that converts float-point arithmetic to decimal form, and creates a comma separated string from a number.
- Use Number.prototype.toLocaleString() to convert the number to decimal mark format.
Sample Solution:
JavaScript Code:
//#Source https://bit.ly/2neWfJ2
const toDecimalMark = num => num.toLocaleString('en-US');
console.log(toDecimalMark(12305030388.9087));
console.log(toDecimalMark(123.2264))
console.log(toDecimalMark(-100.10))
Sample Output:
12,305,030,388.909 123.226 -100.1
Flowchart:

Live Demo:
See the Pen javascript-basic-exercise-125-1 by w3resource (@w3resource) on CodePen.
Improve this sample solution and post your code through Disqus
Previous: Write a JavaScript program to reduce a given Array-like into a value hash (keyed data store).
Next: Write a JavaScript program to create a specified currency formatting from a given number.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join