If you explicitly cast double
to int
, the decimal part will be truncated. For example:
int x = (int) 4.97542; //gives 4 only int x = (int) 4.23544; //gives 4 only
Moreover, you may also use Math.floor()
method to round values in case you want double
value in return.
Related Posts:
- How do I convert a String to an int in Java?
- How to round a number to n decimal places in Java
- How to convert a char to a String?
- Convert String to double in Java
- How can I convert a char to int in Java? [duplicate]
- Create ArrayList from array
- Converting double to integer in Java
- Round a double to 2 decimal places [duplicate]
- Round a double to 2 decimal places [duplicate]
- Round a double to 2 decimal places
- Convert an integer to an array of characters : java
- Converting Hexadecimal String to Decimal Integer
- Always Round UP a Double
- Using Math.round to round to one decimal place?
- Converting from byte to int in Java
- Conversion from Long to Double in Java
- Initialization of an ArrayList in one line
- Is there a Heap in java?
- What’s the difference between map() and flatMap() methods in Java 8?
- Why do we need copy constructor and when should we use copy constructor in java
- What are the -Xms and -Xmx parameters when starting JVM?
- How to match “any character” in regular expression?
- Cannot make a static reference to the non-static method fxn(int) from the type Two
- How to implement a tree data-structure in Java?
- Difference between StringBuilder and StringBuffer
- Iterate through a HashMap [duplicate]
- Non-static variable cannot be referenced from a static context
- JAVA invalid maximum heap size. The specified size exceeds the maximum representable size
- JDK9: An illegal reflective access operation has occurred. org.python.core.PySystemState
- A long bigger than Long.MAX_VALUE
- How to remove single character from a String
- Unsupported major.minor version 52.0 [duplicate]
- Usage of @see in JavaDoc?
- Hadoop “Unable to load native-hadoop library for your platform” warning
- Unreported exception java.lang.Exception; must be caught or declared to be thrown
- How to clear the console?
- How to capitalize the first letter of a String in Java?
- Scanner vs. BufferedReader
- Raw use of parameterized class
- :: (double colon) operator in Java 8
- What does ‘0’ do in Java?
- Service will not start: error 1067: the process terminated unexpectedly
- What is “String args[]”? parameter in main method Java
- “A java exception has occurred” when opening .jar
- How do I set environment variables from Java?
- Exception in thread “main” java.lang.ArrayIndexOutOfBoundsException: 0 error in Java
- What’s the advantage of load() vs get() in Hibernate?
- What Java ORM do you prefer, and why?
- Using Enum values as String literals
- How to change a package name in Eclipse?
- Are arrays passed by value or passed by reference in Java?
- How do I get “Press any key to continue” to work in my Java code?
- What does “?” mean in Java? [duplicate]
- What is the difference between a local variable, an instance field, an input parameter, and a class field?
- Error: Selection does not contain a main type
- TreeMap sort by value
- Encrypt Password in Configuration Files?
- Could not find method compile() for arguments Gradle
- How can I get the current stack trace in Java?
- java.util.zip.ZipException: error in opening zip file
- paint() and repaint() in Java
- Good Hash Function for Strings
- Error – Illegal static declaration in inner class
- Bubble Sort Manually a Linked List in Java
- Checking Password Code
- java – how to create and manipulate a bit array with length of 10 million bits
- What is the difference between object-oriented languages and non object-oriented languages?
- ArrayList<> cannot be resolved to a type
- Exception in thread “main” java.lang.StringIndexOutOfBoundsException: String index out of range: 0
- Error: Main method not found in class Calculate, please define the main method as: public static void main(String[] args) [duplicate]
- ArrayList<> cannot be resolved to a type
- Simple way to repeat a string
- Unreachable statement compile error in Java
- Reflection generic get field value
- error: incompatible types: char cannot be converted to String – Java
- mongoDB, connection refused
- Displaying Image in Java
- How to check the input is an integer or not in Java?
- Efficient way to do batch INSERTS with JDBC
- wrong ELF class: ELFCLASS32
- Invalid signature file digest for Manifest main attributes exception while trying to run jar file
- JAVA + try catch(FileNotFoundException e) going in catch(Exception e)?
- Using a do-while loop to check a User’s input in Java
- What is the proper annotation since @SpringApplicationConfiguration, @WebIntegration, is deprecated in Spring Boot Framework?
- How to write a test class to test my code?
- A beginner’s error (args[0]) [duplicate]
- When/why to call System.out.flush() in Java
- Throwing multiple exceptions in Java
- How can I wait for 10 second without locking application UI in android [duplicate]
- Java error “Value of local variable is not used”
- Is there a way to end the program if statement is false?
- ArithmeticException: “Non-terminating decimal expansion; no exact representable decimal result”
- convert string to arraylist
in java - how to use drawArc()
- How to add RGB values into setColor() in Java?
- Can you write virtual functions / methods in Java?
- Creating video player using Java
- Can I override and overload static methods in Java?
- How can i fix this equals on primitive type(int)
- Split string into array of character strings