ImageScience 3.0.0

imagescience.utility
Class Formatter

java.lang.Object
  extended by imagescience.utility.Formatter

public class Formatter
extends java.lang.Object

Converts floating-point numbers to formatted strings.


Constructor Summary
Formatter()
          Default constructor.
 
Method Summary
 void chop(double limit)
          Sets the limit below which numbers are chopped to 0 by method d2s(double).
 java.lang.String d2s(double d)
          Returns a String representation of a double value.
 void decs(int n)
          Sets the maximum number of decimals used by method d2s(double).
 void inf(java.lang.String inf)
          Sets the string representation of an infinite value used by method d2s(double).
 void nan(java.lang.String nan)
          Sets the string representation of the value Double.NaN used by method d2s(double).
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Formatter

public Formatter()
Default constructor.

Method Detail

chop

public void chop(double limit)
Sets the limit below which numbers are chopped to 0 by method d2s(double).

Parameters:
limit - The chop limit. The absolute value is taken and the default is 10-10. Numbers whose absolute value is less than the limit are considered 0.

decs

public void decs(int n)
Sets the maximum number of decimals used by method d2s(double).

Parameters:
n - The maximum number of decimals used by method d2s(double). Must be larger than or equal to 0 and less than or equal to 10. The default number of decimals used is 1.
Throws:
java.lang.IllegalArgumentException - If n is out of range.

nan

public void nan(java.lang.String nan)
Sets the string representation of the value Double.NaN used by method d2s(double).

Parameters:
nan - The string representation of the value Double.NaN used by method d2s(double). The default string is "NaN".
Throws:
java.lang.NullPointerException - If nan is null.

inf

public void inf(java.lang.String inf)
Sets the string representation of an infinite value used by method d2s(double).

Parameters:
inf - The string representation of an infinite value used by method d2s(double). The default string is "Inf", which translates to "+Inf" for the value Double.POSITIVE_INFINITY, and "-Inf" for the value Double.NEGATIVE_INFINITY.
Throws:
java.lang.NullPointerException - If inf is null.

d2s

public java.lang.String d2s(double d)
Returns a String representation of a double value.

Parameters:
d - The double value to be represented.
Returns:
A new String object containing a string representation of d. The maximum number of decimals used in representing d can be specified with method decs(int). The value of d is rounded to the specified maximum number of decimals. The returned string will contain less than the maximum number of decimals if d can be represented exactly that way. In particular, if d is equal to an integer value, the returned string represents that integer value, without decimals and preceding decimal separator symbol. The string returned when Double.isNaN(d) yields true can be specified with method nan(String). Similarly, the string returned when Double.isInfinite(d) yields true can be specified with method inf(String). The returned string is "0" if the absolute value of d is less than the limit set with method chop(double).

ImageScience 3.0.0

Copyright (C) Erik Meijering. Permission to use this software and corresponding documentation for educational, research, and not-for-profit purposes, without a fee and without a signed licensing agreement, is granted, subject to the following terms and conditions.

IT IS NOT ALLOWED TO REDISTRIBUTE, SELL, OR LEASE THIS SOFTWARE, OR DERIVATIVE WORKS THEREOF, WITHOUT PERMISSION IN WRITING FROM THE COPYRIGHT HOLDER. THE COPYRIGHT HOLDER IS FREE TO MAKE VERSIONS OF THE SOFTWARE AVAILABLE FOR A FEE OR COMMERCIALLY ONLY.

IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OF ANY KIND WHATSOEVER, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF ADVISED OF THE POSSIBILITY THEREOF.

THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE EXPRESS OR IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE AND CORRESPONDING DOCUMENTATION IS PROVIDED "AS IS". THE COPYRIGHT HOLDER HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.