Get the smallest double greater than the given value


 

Get the smallest double greater than the given value

This section demonstrates you how to get the smallest double value greater than the given value.

This section demonstrates you how to get the smallest double value greater than the given value.

Get the smallest double greater than the given value

This section demonstrates you how to get the smallest double value greater than the given value.

Java has provide several classes for formatting different objects like, number, date, time, message etc. For numbers, there is a class ChoiceFormat which is a concrete subclass of NumberFormat class and is responsible for formatting a range of numbers. It maps numerical ranges to string. Here we have to find the new value that will be as close as possible to the original but still strictly greater than the original.

In the given example, first of all, we have specified a value of double type. Now to determine it, we have invoked the nextDouble() method of ChoiceFormat class. This method specify the limits used by a ChoiceFormat and generate the new smallest double value which greater than the specified double value.

Here is the code:

import java.text.ChoiceFormat;

public class GetSmallestValueGreaterThanGivenValue {
	public static void main(String[] argv) throws Exception {
		double num = 5.5;
		double value = ChoiceFormat.nextDouble(num);
		System.out.println(value);
	}
}

Output

5.500000000000001

Ads