Java Program to Illustrate the Usage of Floating Last Updated : 07 Sep, 2021 Comments Improve Suggest changes Like Article Like Report The floating-point number are those number which needs fractional precision that is the number that can be in the fraction. There many more mathematical calculations in which floating type is involved. For e.g. finding the square root of a number up to certain decimal values finding the cube root of the number, finding roots of quadratic equation, and calculation involving trigonometric functions like sin cos tan. There are two types of floating-point data type FloatDoubleNameWidthRangeFloat321.4e–045 to 3.4e+038Double644.9e–324 to 1.8e+308Float: It is a single-precision value that has 32 bits in storage. and this single precision is faster and does take less size compared to double precision. For java variables, we can use float while declaring or initializing for expected value to be fractional. The default value in java is 0.0f and its size is 4 bytes. Float in java can have negative values. The correct ways and incorrect ways of defining java floating-point. float a1=10.57f which is equal to 10.57float a2 =10f it is equal to 10.0float a3=9.58 it will give an error. Here we concluded that if we are initializing any value with float it ends with f then it is correct otherwise it will throw an error. Printing float values: Java // Java Program to Illustrate the Usage of Floating import java.io.*; public class GFG { public static void main(String[] args) { // initialized two float variables with // the least and max value of float float a1 = 1.40129846432481707e-45f; float a2 = 3.40282346638528860e+38f; // printed the value of a1 and a2 System.out.println("Start range: " + a1); System.out.println("End range: " + a2); } } OutputStart range: 1.4E-45 End range: 3.4028235E38 Multiplication of float values: Java // Java Program to Illustrate the Usage of Floating import java.io.*; public class GFG { public static void main(String[] args) { // initialized two float variables a1 and a2. // declared n3 which will contain // the output of a1 * a2. float a1 = 10.89f; float a2 = 7.43f; float a3; // multiplied n1 and n2 and stored it in a3 a3 = a1 * a2; // printed the value of a3 System.out.println("The result of n1 x n2 is: " + a3); } } OutputThe result of n1 x n2 is: 80.912704 Providing value in Scientific notation Java // Java Program to Illustrate the Usage of Floating import java.io.*; public class GFG { public static void main(String[] args) { // initialized two float variables a1 and a2. // a1 has simple value of float type and a2 // has the equivalent scientific notation. float a1 = 283.75f; float a2 = 2.8375e2f; // printed the value of a1 and a2 System.out.println("Simple Float: " + a1); System.out.print("Scientific Notation: " + a2); } } OutputSimple Float: 283.75 Scientific Notation: 283.75 Comment More infoAdvertise with us Next Article Java Program to Illustrate the Usage of Floating viv_007 Follow Improve Article Tags : Java Technical Scripter Java Programs Technical Scripter 2020 Practice Tags : Java Similar Reads Java Program to Convert String to Float Value Given a string âstrâ in Java, the task is to convert this string to float type. Methods: This can be done by two methods as listed below: Using parseFloat() Method Using valueOf() Method Let us discuss above two ways of implementing the methods to get a fair understanding of the conversion of string 4 min read Java Program to Convert a Float value to String Given a Float value in Java, the task is to write a Java program to convert this float value to string type. Examples: Input: 1.0 Output: "1.0" Input: 3.14 Output: "3.14" Strings - Strings in Java are objects that are supported internally by a char array. Since arrays are immutable, and strings are 4 min read Java Program to Multiply two Floating-Point Numbers The float class is a wrapper class for the primitive type float which contains several methods to effectively deal with a float value like converting it to a string representation, and vice-versa. An object of the Float class can hold a single float value. The task is to multiply two Floating point 1 min read Java Program to Convert Double to String The primary goal of double to String conversion in Java is to store big streams of numbers that are coming where even data types fail to store the stream of numbers. It is generically carried out when we want to display the bigger values. In this article, we will learn How to Convert double to Strin 3 min read Java Program to Show the Nesting of Methods In java, the methods and variables which we create in a class can only be called by using the object of that class or, in case of static methods, we can directly call it by using the name of the class. The methods and variables can be called with the help of the dot operator. But there is a special 5 min read Java Program to Round a Number to n Decimal Places Floating-point numbers are decimal values, which can be rounded to n number of decimal places. There are 3 different ways to Round a Number to n Decimal Places in Java as follows: Using format MethodUsing DecimalFormat ClassMultiply and Divide the number by 10n (n decimal places) Example: Input: num 4 min read Convert String to Float in Java To convert a String to a Float in Java, there are several ways including built-in methods and handling potential exceptions for invalid inputs.Example: For this conversion, we will use the most common and efficient method i.e. parseFloat() method. This method converts a string into a primitive float 2 min read Java Programs - Java Programming Examples In this article, we will learn and prepare for Interviews using Java Programming Examples. From basic Java programs like the Fibonacci series, Prime numbers, Factorial numbers, and Palindrome numbers to advanced Java programs.Java is one of the most popular programming languages today because of its 8 min read Java Exercises - Basic to Advanced Java Practice Programs with Solutions Looking for Java exercises to test your Java skills, then explore our topic-wise Java practice exercises? Here you will get 25 plus practice problems that help to upscale your Java skills. As we know Java is one of the most popular languages because of its robust and secure nature. But, programmers 7 min read Java Object Oriented Programming - Exercises Looking for Java OOP exercises to test and improve your object-oriented programming skills? Explore our topic-wise Java OOP practice exercises, featuring over 25 practice problems designed to help you master key OOP concepts such as encapsulation, inheritance, polymorphism, and abstraction. Java is 15+ min read Like