Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

77
Views
I need to know how to read an input from a html form in JavaScript and separate the digits after the decimal point

For example, if the number put in the html form was 30.1 I need to separate the 30 from the 1 in javascript thanks Ben

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

You need to convert it to string first, then use String.prototype.split method. For example

const value = 30.1;
const separated = `${value}`.split("."); // output will be ["30", "1"]
console.log(separated[0], separated[1]) // "30", "1"

if you want to read it as number, you can use Number()

console.log(Number(separated[0]), Number(separated[1])) // 30, 1
about 4 years ago · Juan Pablo Isaza Report

0

It's mandatory to convert number into String for split

let number = 30.1;
let convertToString = String(number);
let splitNumber = convertToString.split(".");
for(let i = 0; i < splitNumber.length; i++)
{
  console.log(splitNumber[i]);
}
about 4 years ago · Juan Pablo Isaza Report

0

you should convert the number into string then using spilt methode

let num = 40.1
let value = num.toString().split('.');
console.log(value)

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!