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

287
Views
Determine if string is string, int, or float

All of my inputs are strings. I want to export them to a sort of DB, using the correct type.

So I can have inputs like e.g. "hello123", "123", or "123.0".
Which have the type string, int, and float respectively.

I already have a decent function determining whether it's a number or not:

const isNumber = (input) => !isNaN(Number(input))

console.log(isNumber("123hello")) // false
console.log(isNumber("123"))      // true
console.log(isNumber("123.0"))    // true

But I would like something like:

const getType = (input) => {
  if (/* check if int */) {
    return 'int'
  } else if (/* check if float */) {
    return 'float'
  } else {
    return 'string'
  }
}

console.log(getType("123hello")) // 'string'
console.log(getType("123"))      // 'int'
console.log(getType("123.0"))    // 'float' (preferably, but 'int' is also ok)
about 4 years ago · Juan Pablo Isaza
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!