Cast Double to Integer in Java
Posted By: Anonymous
Any way to cast java.lang.Double
to java.lang.Integer
?
It throws an exception
“java.lang.ClassCastException: java.lang.Double incompatible with java.lang.Integer”
Solution
A Double
is not an Integer
, so the cast won’t work. Note the difference between the Double
class and the double
primitive. Also note that a Double
is a Number
, so it has the method intValue
, which you can use to get the value as a primitive int
.
Answered By: Anonymous
Related Articles
- Polymer dart: Data bind integer value to String attribute
- Callback functions in C++
- Form field border-radius is not working only on the…
- How can I throw CHECKED exceptions from inside Java…
- Throw HttpResponseException or return…
- Why is 2 * (i * i) faster than 2 * i * i in Java?
- Fastest way to iterate over all the chars in a String
- Javax.net.ssl.SSLHandshakeException:…
- What is a NullReferenceException, and how do I fix it?
- Adding gif image in an ImageView in android
- Do you (really) write exception safe code?
- What is an IndexOutOfRangeException /…
- Knight's tour Problem - storing the valid moves then…
- problem with client server unix domain stream…
- Undefined reference to 'vtable for ✘✘✘'
- UnsatisfiedDependencyException: Error creating bean…
- Why does Spring security throw exception…
- Convert NSNumber to int in Objective-C
- IOException: read failed, socket might closed -…
- WAVE file unexpected behaviour
- How to filter a RecyclerView with a SearchView
- C++ OpenGL stb_image.h errors
- Why is "throws Exception" necessary when calling a function?
- ValueError: invalid literal for int () with base 10
- Palindromic numbers in Java
- How do I compare two Integers?
- What does "Fatal error: Unexpectedly found nil while…
- ASP.NET Core Web API exception handling
- Draw in Canvas by finger, Android
- Drawing a simple line graph in Java
- What's the best way to get the last element of an…
- How the int.TryParse actually works
- How do I use Assert.Throws to assert the type of the…
- Calculate time difference in minutes in SQL Server
- Accessing a Shared File (UNC) From a Remote,…
- How do Mockito matchers work?
- How do I convert a float number to a whole number in…
- Auto-fit TextView for Android
- Checking if a variable is an integer in PHP
- How to create an Array, ArrayList, Stack and Queue in Java?
- Baffling variadic templates exercise
- Handling InterruptedException in Java
- How to print binary tree diagram?
- Is it possible to print a variable's type in standard C++?
- How to cast an Object to an int
- Manually raising (throwing) an exception in Python
- What are the nuances of scope prototypal /…
- C Argument number to create PGM images
- force view to be updated from within a valueconverter
- How using try catch for exception handling is best practice
- Design DFA accepting binary strings divisible by a…
- Implementation of user defined array on stack and/or…
- How to convert number to words in java
- Why are elementwise additions much faster in…
- org.springframework.beans.factory.BeanCreationExcept…
- Reference — What does this symbol mean in PHP?
- How to avoid a System.Runtime.InteropServices.COMException?
- Understanding checked vs unchecked exceptions in Java
- C++ error: expected class member or base class name…
- Could not commit JPA transaction: Transaction marked…
- Why is "except: pass" a bad programming practice?
- Vue Js - Why do changes to data not update the view…
- C# int to byte[]
- How to Update Database from Assets Folder in App
- How can I view the source code for a function?
- Getting infinite loop after entering 2 objects to…
- String to byte array in php
- Difference between
- Explanation on Integer.MAX_VALUE and…
- Conversion failed when converting the varchar value…
- Converting from byte to int in java
- What is the difference between Integer and int in Java?
- Why does this core dumped error happen in my class?…
- ObjectiveC Parse Integer from String
- How to end C++ code
- How to convert Integer to int?
- How to solve the problem in Javascript code to…
- Java - get pixel array from image
- I have tried to implement mergesort and am unable to…
- How to convert an ArrayList containing Integers to…
- Mock MQRFH2 header in JUnit Testing Error [MQRFH2…
- I do not use TBB, but I get linker errors related to TBB
- Builder pattern without inner class
- Program.Mattor(): not all code paths return a value.…
- How to pass 2D array (matrix) in a function in C?
- Converting Oracle SQL Procedure into MySQL Stored Procedure
- EL access a map value by Integer key
- C compile error: Id returned 1 exit status
- How to format a phone number in a textfield
- Autowiring fails: Not an managed Type
- Representing null in JSON
- C - determine if a number is prime
- How to create custom exceptions in Java?
- Throwing a exception with custom message from…
- How to create ranges and synonym constants in C#?
- long long int vs. long int vs. int64_t in C++
- Catching FULL exception message
- Head pointer not accessible when creating a method…
- SQL query return data from multiple tables
- After a little scroll, the sticky navbar just is not…
Disclaimer: This content is shared under creative common license cc-by-sa 3.0. It is generated from StackExchange Website Network.