Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8589383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:02:42+00:00 2026-06-11T23:02:42+00:00

My program receives some input (a String ). It is rather possible that the

  • 0

My program receives some input (a String). It is rather possible that the input is in the form of a double, like "1.5". But I would like to convert it to an integer, so I can end up with just a 1.

First, I tried this:

Integer.parseInt(someString);

But it doesn’t work – I’m assuming it is because of the dot . that it can’t parse it.

So I thought that maybe the Integer class can create an integer from a double. So I decided to create a double and then make it an int, like this:

Integer.parseInt(Double.parseDouble(someString));

But apparently there is

no suitable method found for parseInt(double)

So, what do you suggest? Are there one-liners for this? I thought about making a method that removes the dot and all characters after it… but that doesn’t sound very cool.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T23:02:44+00:00Added an answer on June 11, 2026 at 11:02 pm

    It is safe to parse any numbers as double, then convert it to another type after. Like this:

    // someString = "1.5";
    double val = Double.parseDouble(someString);  // -> val = 1.5;
    int intVal = (int) Math.floor(val);           // -> intVal = 1;
    

    Note that with Java 7 (not tested with earlier JVM, but I think it should work too), this will also yield the same result as above :

    int intVal = (int) Double.parseDouble(someString);
    

    as converting from a floating value to an int will drop any decimal without rounding.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say that my program receives an input such as a string of characters
I'm trying to write a payroll program that simply receives input, does some calculations
I am writing a small program in C++ that receives mic input and does
I have a program that receives real time data on 1000 topics. It receives
i have a program that receives data from a wireless device over bluetooth...i now
I have a program that receives webcam video and displays it on a C#
I have a c++/windows program that receives data from another c++ program via a
I need to write a program in 8086 Assembly that receives data from the
i'm trying to create a bridge program in twisted.web that receives data from a
I have a bug in a multi-processes program. The program receives input and instantly

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.