<script src="https://unpkg.com/react@17.0.2/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom@17.0.2/umd/react-dom.development.js"></script>
<script src="https://unpkg.com/@babel/standalone@7.14.7/babel.min.js"></script>
<script type="text/babel">
function formatNumberWithHyphen(number) {
// Convert the number to a string and remove any non-digit characters
const cleanNumber = String(number).replace(/\D/g, "");
// Define the number of digits in each group
// Split the cleanNumber into groups of digits from right to left
let startIndex = cleanNumber.length;
const endIndex = startIndex;
startIndex = Math.max(0, startIndex - digitsInGroup);
groups.unshift(cleanNumber.slice(startIndex, endIndex));
// Join the groups with hyphens and return the formatted string
function FormatNumberApp() {
const numberToFormat = 1234567890;
<div className='container'>
<h3>React js format number - hypen seperated</h3>
<p>Original number: {numberToFormat}</p>
<p>Formatted number: {formatNumberWithHyphen(numberToFormat)}</p>
ReactDOM.render(<FormatNumberApp />, document.getElementById("app"));
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
font-family: Arial, sans-serif;