In this tutorial learn how you can write a program to convert double to float in java. We use the Scanner class for user input and convert it to float.
Java is a high-level, class-based, object-oriented programming language that is designed to have as few implementation dependencies as possible.
Here is the code to convert double to float in Java programming.
//Write a Java program to convert double to float. import java.util.Scanner; public class Doubles { public static void main(String args[]) { Scanner input = new Scanner(System.in); System.out.println("Enter any number in double:"); double number = input.nextDouble(); float result = (float)number; System.out.println("Double converted to float: " + result + "."); input.close(); } }
This is how you can write a program to convert double to float in java programming. Comment below if you like our tutorial.