Home Tutorial Java Corejava Javatext Get the smallest double greater than the given value

 
 

Share on Google+Share on Google+
Get the smallest double greater than the given value
Posted on: October 13, 2010 at 12:00 AM
Advertisement
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
Advertisement

Related Tags for Get the smallest double greater than the given value:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: October 13, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com