JAVA
public class Main {
public static void main(String[] args) {
double myDouble = 9.78d;
int myInt = (int) myDouble; // Explicit casting: double to int
System.out.println(myDouble);
System.out.println(myInt);
}
}
Explanation :
This Java program demonstrates type casting, specifically converting a double (a floating-point decimal number) into an int (a whole number) using explicit casting.
Here is a step-by-step breakdown:
double myDouble = 9.78d;Declares a variable named
myDoubleof typedoubleand assigns it the value9.78. Thedsuffix explicitly denotes a double literal (though it is optional in Java).int myInt = (int) myDouble;Performs explicit casting (also known as narrowing conversion). Because a
doublecan hold decimals and anintcannot, Java requires you to explicitly tell it to convert the type by putting(int)in front of the variable.Crucial detail: When casting a floating-point number to an integer, Java truncates the decimal part entirely—it does not round up. Therefore,
9.78becomes9.System.out.println(myDouble);Prints the original
doublevalue to the console:9.78.System.out.println(myInt);Prints the converted integer value to the console:
9.
Output
9.78
9
SQL
Text Fields vs. Numeric Fields
SQL requires single quotes around text values (most database systems will also allow double quotes).
However, numeric fields should not be enclosed in quotes:
Example
SELECT * FROM Customers
WHERE CustomerID = 1;
References
https://www.w3schools.com/sql/sql_where.asp
https://www.w3schools.com/java/java_examples.asp
Top comments (0)