Example usage for java.text NumberFormat format

List of usage examples for java.text NumberFormat format

Introduction

In this page you can find the example usage for java.text NumberFormat format.

Prototype

public final String format(long number) 

Source Link

Document

Specialization of format.

Usage

From source file:com.levien.audiobuffersize.AudioBufferSize.java

JitterMeasurement analyzeDrift(double[] arr, double forceRate) {
    final int startupSkip = 100;
    int n = arr.length / 4;
    // Do linear regression to find timing drift
    double xys = 0, xs = 0, ys = 0, x2s = 0;
    int count = n - startupSkip;
    for (int i = startupSkip; i < n; i++) {
        double x = i;
        double y = arr[i];
        xys += x * y;/*  w w w . ja v a2 s  .co m*/
        xs += x;
        ys += y;
        x2s += x * x;
    }
    double beta = (count * xys - xs * ys) / (count * x2s - xs * xs);
    double jitRate = forceRate == 0 ? beta : forceRate;
    //double alpha = (ys - beta * xs) / count;
    double minJit = 0;
    double maxJit = 0;
    for (int i = startupSkip; i < n; i++) {
        double err = jitRate * i - arr[i];
        if (i == startupSkip || err < minJit)
            minJit = err;
        if (i == startupSkip || err > maxJit)
            maxJit = err;
    }
    JitterMeasurement jm = new JitterMeasurement();
    jm.rate = beta;
    jm.jitter = maxJit - minJit;
    NumberFormat f = NumberFormat.getInstance();
    f.setMinimumFractionDigits(3);
    f.setMaximumFractionDigits(3);
    logUI("ms per tick = " + f.format(jm.rate * 1000) + "; jitter (lr) = " + f.format(jm.jitter * 1000));
    return jm;
}

From source file:com.prowidesoftware.swift.model.field.Field105.java

/**
 * Returns a localized suitable for showing to humans string of a field component.<br>
 *
 * @param component number of the component to display
 * @param locale optional locale to format date and amounts, if null, the default locale is used
 * @return formatted component value or null if component number is invalid or not present
 * @throws IllegalArgumentException if component number is invalid for the field
 * @since 7.8//from w  w w .j a v a2s  . c  o m
 */
@Override
public String getValueDisplay(int component, Locale locale) {
    if (component < 1 || component > 1) {
        throw new IllegalArgumentException("invalid component number " + component + " for field 105");
    }
    if (locale == null) {
        locale = Locale.getDefault();
    }
    if (component == 1) {
        //number or amount
        java.text.NumberFormat f = java.text.NumberFormat.getNumberInstance(locale);
        Number n = getComponent1AsNumber();
        if (n != null) {
            return f.format(n);
        }
    }
    return null;
}

From source file:com.prowidesoftware.swift.model.field.Field120.java

/**
 * Returns a localized suitable for showing to humans string of a field component.<br>
 *
 * @param component number of the component to display
 * @param locale optional locale to format date and amounts, if null, the default locale is used
 * @return formatted component value or null if component number is invalid or not present
 * @throws IllegalArgumentException if component number is invalid for the field
 * @since 7.8/*from  w  ww.  j a  v  a2s  .  c o m*/
 */
@Override
public String getValueDisplay(int component, Locale locale) {
    if (component < 1 || component > 1) {
        throw new IllegalArgumentException("invalid component number " + component + " for field 120");
    }
    if (locale == null) {
        locale = Locale.getDefault();
    }
    if (component == 1) {
        //number or amount
        java.text.NumberFormat f = java.text.NumberFormat.getNumberInstance(locale);
        Number n = getComponent1AsNumber();
        if (n != null) {
            return f.format(n);
        }
    }
    return null;
}

From source file:com.prowidesoftware.swift.model.field.Field125.java

/**
 * Returns a localized suitable for showing to humans string of a field component.<br>
 *
 * @param component number of the component to display
 * @param locale optional locale to format date and amounts, if null, the default locale is used
 * @return formatted component value or null if component number is invalid or not present
 * @throws IllegalArgumentException if component number is invalid for the field
 * @since 7.8/*from   w  w w .j  a v  a 2 s  .  c  o  m*/
 */
@Override
public String getValueDisplay(int component, Locale locale) {
    if (component < 1 || component > 1) {
        throw new IllegalArgumentException("invalid component number " + component + " for field 125");
    }
    if (locale == null) {
        locale = Locale.getDefault();
    }
    if (component == 1) {
        //number or amount
        java.text.NumberFormat f = java.text.NumberFormat.getNumberInstance(locale);
        Number n = getComponent1AsNumber();
        if (n != null) {
            return f.format(n);
        }
    }
    return null;
}

From source file:com.prowidesoftware.swift.model.field.Field126.java

/**
 * Returns a localized suitable for showing to humans string of a field component.<br>
 *
 * @param component number of the component to display
 * @param locale optional locale to format date and amounts, if null, the default locale is used
 * @return formatted component value or null if component number is invalid or not present
 * @throws IllegalArgumentException if component number is invalid for the field
 * @since 7.8/*from  w ww.  ja  v  a  2s  . c om*/
 */
@Override
public String getValueDisplay(int component, Locale locale) {
    if (component < 1 || component > 1) {
        throw new IllegalArgumentException("invalid component number " + component + " for field 126");
    }
    if (locale == null) {
        locale = Locale.getDefault();
    }
    if (component == 1) {
        //number or amount
        java.text.NumberFormat f = java.text.NumberFormat.getNumberInstance(locale);
        Number n = getComponent1AsNumber();
        if (n != null) {
            return f.format(n);
        }
    }
    return null;
}

From source file:com.prowidesoftware.swift.model.field.Field140.java

/**
 * Returns a localized suitable for showing to humans string of a field component.<br>
 *
 * @param component number of the component to display
 * @param locale optional locale to format date and amounts, if null, the default locale is used
 * @return formatted component value or null if component number is invalid or not present
 * @throws IllegalArgumentException if component number is invalid for the field
 * @since 7.8//w  ww.ja v  a2 s  .  com
 */
@Override
public String getValueDisplay(int component, Locale locale) {
    if (component < 1 || component > 1) {
        throw new IllegalArgumentException("invalid component number " + component + " for field 140");
    }
    if (locale == null) {
        locale = Locale.getDefault();
    }
    if (component == 1) {
        //number or amount
        java.text.NumberFormat f = java.text.NumberFormat.getNumberInstance(locale);
        Number n = getComponent1AsNumber();
        if (n != null) {
            return f.format(n);
        }
    }
    return null;
}

From source file:com.prowidesoftware.swift.model.field.Field144.java

/**
 * Returns a localized suitable for showing to humans string of a field component.<br>
 *
 * @param component number of the component to display
 * @param locale optional locale to format date and amounts, if null, the default locale is used
 * @return formatted component value or null if component number is invalid or not present
 * @throws IllegalArgumentException if component number is invalid for the field
 * @since 7.8/*from  w w  w  .  j  a  va2s  . c o m*/
 */
@Override
public String getValueDisplay(int component, Locale locale) {
    if (component < 1 || component > 1) {
        throw new IllegalArgumentException("invalid component number " + component + " for field 144");
    }
    if (locale == null) {
        locale = Locale.getDefault();
    }
    if (component == 1) {
        //number or amount
        java.text.NumberFormat f = java.text.NumberFormat.getNumberInstance(locale);
        Number n = getComponent1AsNumber();
        if (n != null) {
            return f.format(n);
        }
    }
    return null;
}

From source file:com.prowidesoftware.swift.model.field.Field14C.java

/**
 * Returns a localized suitable for showing to humans string of a field component.<br>
 *
 * @param component number of the component to display
 * @param locale optional locale to format date and amounts, if null, the default locale is used
 * @return formatted component value or null if component number is invalid or not present
 * @throws IllegalArgumentException if component number is invalid for the field
 * @since 7.8/*from  ww  w  . j a  v a 2 s. c  om*/
 */
@Override
public String getValueDisplay(int component, Locale locale) {
    if (component < 1 || component > 1) {
        throw new IllegalArgumentException("invalid component number " + component + " for field 14C");
    }
    if (locale == null) {
        locale = Locale.getDefault();
    }
    if (component == 1) {
        //number or amount
        java.text.NumberFormat f = java.text.NumberFormat.getNumberInstance(locale);
        Number n = getComponent1AsNumber();
        if (n != null) {
            return f.format(n);
        }
    }
    return null;
}

From source file:com.prowidesoftware.swift.model.field.Field151.java

/**
 * Returns a localized suitable for showing to humans string of a field component.<br>
 *
 * @param component number of the component to display
 * @param locale optional locale to format date and amounts, if null, the default locale is used
 * @return formatted component value or null if component number is invalid or not present
 * @throws IllegalArgumentException if component number is invalid for the field
 * @since 7.8// w  ww.j  av a  2  s  .  c  om
 */
@Override
public String getValueDisplay(int component, Locale locale) {
    if (component < 1 || component > 1) {
        throw new IllegalArgumentException("invalid component number " + component + " for field 151");
    }
    if (locale == null) {
        locale = Locale.getDefault();
    }
    if (component == 1) {
        //number or amount
        java.text.NumberFormat f = java.text.NumberFormat.getNumberInstance(locale);
        Number n = getComponent1AsNumber();
        if (n != null) {
            return f.format(n);
        }
    }
    return null;
}

From source file:com.prowidesoftware.swift.model.field.Field152.java

/**
 * Returns a localized suitable for showing to humans string of a field component.<br>
 *
 * @param component number of the component to display
 * @param locale optional locale to format date and amounts, if null, the default locale is used
 * @return formatted component value or null if component number is invalid or not present
 * @throws IllegalArgumentException if component number is invalid for the field
 * @since 7.8//ww  w . j  a  va2s . c om
 */
@Override
public String getValueDisplay(int component, Locale locale) {
    if (component < 1 || component > 1) {
        throw new IllegalArgumentException("invalid component number " + component + " for field 152");
    }
    if (locale == null) {
        locale = Locale.getDefault();
    }
    if (component == 1) {
        //number or amount
        java.text.NumberFormat f = java.text.NumberFormat.getNumberInstance(locale);
        Number n = getComponent1AsNumber();
        if (n != null) {
            return f.format(n);
        }
    }
    return null;
}