Java by API/java.text/ChoiceFormat

Материал из Java эксперт
Перейти к: навигация, поиск

ChoiceFormat: nextDouble(double d)

   <source lang="java">

import java.text.ChoiceFormat; public class Main {

 public static void main(String[] argv) throws Exception {
   double d = 1.2;
   double d2 = ChoiceFormat.nextDouble(d);
   System.out.println(d2);
 }

} //1.2000000000000002

 </source>
   
  
 
  



ChoiceFormat: previousDouble(double d)

   <source lang="java">

import java.text.ChoiceFormat; public class Main {

 public static void main(String[] argv) throws Exception {
   double d = 1.2;
   // Get the largest double less than d
   double d1 = ChoiceFormat.previousDouble(d);
   System.out.println(d1);
 }

} //1.1999999999999997

 </source>
   
  
 
  



new ChoiceFormat(double[] limits, String[] formats)

   <source lang="java">

import java.text.ChoiceFormat; public class Main {

 public static void main(String args[]) {
   double limits[] = { 0.0, 0.1, 0.3, 0.7 };
   String labels[] = { "very low", "low", "moderate", "high" };
   ChoiceFormat format = new ChoiceFormat(limits, labels);
   double r = Math.random();
   
   System.out.println(format.format(r) + " (" + r + ").");
 }

} //high (0.755370803805559).

 </source>