About 593,000 results
Open links in new tab
  1. How can I convert a decimal string value to int in java

    Aug 12, 2021 · Convert the string to an integer, then parse: int i = Integer.parseInt(str.replaceAll("\\..*", "")); This removes the dot and everything after it, which is effectively what casting a floating point type to integer does.

  2. How to convert decimal value stored in a string to integer in java?

    Jul 30, 2017 · Use int i = (int) Double.parseDouble("1490.20"); to convert it to an integer, but to keep the decimal, just use double d = Double.parseDouble("1490.20");.

  3. java - How to change decimal value string into int without …

    Sep 23, 2022 · I am working on a pretty old Java application and I can not change Integer field to something else which can hold decimal values, so I need to convert some decimal string like "100.00", "3.33" "33.44" to Integer without loosing fractional values. String stringValue = "100.00";

  4. Java Convert String to Int - TechBeamers

    Apr 13, 2025 · Convert a Java string to int using the Integer.parseInt(), valueOf(), and 8 more methods with examples, guidance to use, tips, and FAQs.

  5. How to Convert a Decimal String to an Integer in Java

    To convert a decimal string to an integer, first parse it as a `double` or `float` and then cast the result to an `int`. Use `Double.parseDouble()` or `Float.parseFloat()` to first convert to a floating-point number before casting to an integer.

  6. Convert String to int in Java (with Examples) - HowToDoInJava

    Jan 10, 2023 · learned to parse a string (decimal, octal and hexadecimal) to int or Integer types using Integer.parseInt (), valueOf () and decode () methods. Learn to convert a Java String to int value. Note that string can contain a normal decimal value or a different value in other bases or radix. 1. Using Integer.parseInt () 1.1. Syntax.

  7. How to Convert a String to an int in Java? - GeeksforGeeks

    Nov 25, 2024 · Converting a String to an int in Java can be done using methods provided in the Integer class, such as Integer.parseInt() or Integer.valueOf() methods. Example: The most common method to convert a string to a primitive int is Integer.parseInt().

  8. How To Convert Java String To Int – Tutorial With Examples

    Apr 1, 2025 · This tutorial explains the ways to convert Java String to Integer using Integer.parseInt and Integer.ValueOf methods with code examples.

  9. Convert string to decimal number with 2 decimal places in Java

    Jan 16, 2017 · Java convert a String to decimal: String dennis = "0.00000008880000"; double f = Double.parseDouble(dennis); System.out.println(f); System.out.println(String.format("%.7f", f)); System.out.println(String.format("%.9f", new BigDecimal(f))); System.out.println(String.format("%.35f", new BigDecimal(f))); System.out.println(String.format("%.2f ...

  10. How do I convert a String to an int in Java? - W3docs

    How do I convert a String to an int in Java? To convert a String to an int in Java, you can use the parseInt() method of the Integer class. Here's an example: int num = Integer.parseInt(str); The parseInt() method takes a String as an argument and returns the corresponding int value.

Refresh