is there a possibility that casting a double created via
Math.round()
will still result in a truncated down number
No, round()
will always round your double to the correct value, and then, it will be cast to an long
which will truncate any decimal places. But after rounding, there will not be any fractional parts remaining.
Here are the docs from Math.round(double)
:
Returns the closest long to the argument. The result is rounded to an integer by adding 1/2, taking the floor of the result, and casting the result to type long. In other words, the result is equal to the value of the expression:
(long)Math.floor(a + 0.5d)
Related Posts:
- Convert String to double 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
- How to round a number to n decimal places in Java
- How do I limit the number of decimals printed for a double?
- How do I limit the number of decimals printed for a double?
- Double array initialization in Java
- Convert an integer to an array of characters : java
- Always Round UP a Double
- If Java is Strongly typed then why does this code compile?
- Double decimal formatting in Java
- Double cannot be dereferenced?
- How to implement infinity in Java?
- Using Math.round to round to one decimal place?
- How can I truncate a double to only two decimal places in Java?
- Java double.MAX_VALUE?
- How can I truncate a double to only two decimal places in Java?
- How to cast ArrayList<> from List<>
- What do F and D mean at the end of numeric literals?
- Convert boolean to int in Java
- Convert double to Int, rounded down
- Java ArrayList of Doubles
- How to cast ArrayList<> from List<>
- What is the difference between “Double” and “double” in Java?
- Why cannot cast Integer to String in java?
- Convert float to double without losing precision
- Java rules for casting
- Convert double to float 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?
- How to create a sub array from another array in Java?
- “Missing return statement” within if / for / while
- A JNI error has occurred, please check your installation and try again in Eclipse x86 Windows 8.1
- in java what does the @ symbol mean?
- How to call a method in another class in Java?
- unreported exception java.io.FileNotFoundException; must be caught or declared to be thrown
- Error creating bean with name ‘entityManagerFactory’ defined in class path resource : Invocation of init method failed
- Java, “Variable name” cannot be resolved to a variable
- How to convert a Binary String to a base 10 integer in Java
- Java Method Stubs
- What’s the purpose of META-INF?
- How can I represent a range in Java?
- How to solve error: ‘;’ expected in Java?
- Making a Java Makefile
- Censored Words Condition
- method in class cannot be applied to given types
- unused import statement for used ones in IntelliJ IDEA
- Unsigned long in Java
- Integer range when using 64bit jdk
- Removing whitespace from strings in Java
- what is this ANT build?
- Eclipse Java error: This selection cannot be launched and there are no recent launches
- align text center with android
- hat is the purpose of flush() in Java streams?
- How can I convert integer into float in Java?
- How can I avoid this Ant Build error?
- Java Comparator class to sort arrays
- (The Triangle class) Design a class named Triangle that extends GeometricObject
- Cannot assign requested address using ServerSocket.socketBind
- Consider defining a bean of type ‘package’ in your configuration [Spring-Boot]
- Java – How to do floor division?
- Short form for Java if statement
- How to read json file into java with simple JSON library
- How can I convert a long to int in Java?
- org.apache.jasper.JasperException: Unable to compile class for JSP:
- How do I parse command line arguments in Java?
- Missing method body, or declare abstract in Java
- java code is showing error. ( ‘;’,expected)
- Efficient swapping of elements of an array in Java
- Empty an array in Java / processing
- Class is not Abstract and does not Override error in Java
- hibernate properties not found
- Make a simple timer in Java
- How to switch scenes in JavaFX
- Corrupt jar file
- ReferenceError: “alert” is not defined
- Must issue a STARTTLS command first
- How to convert a String to CharSequence?
- Aspect Ratio with 800×480
- How do I convert a String to a BigInteger?
- How to set JAVA_HOME in Linux for all users
- What is ‘PermSize’ in Java?
- Jackson with JSON: Unrecognized field, not marked as ignorable
- Create a two dimensional string array anArray[2][2]
- 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)