Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to Split number with comma after two digit and store into two variables in javascript?

I have a variable var Number = 2425;
I want to break it into two parts and store into into two different variables.

var data = 24;
var month = 25;

How can I get this in javaScript.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Coerce the number to a string, and then use substring to get the relevant characters.

const number = 2425;

const str = String(number);

const data = str.substring(0, 2);
const month = str.substring(2);

console.log(data, month);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading