Java Array arrayStringR(double[] data)

Here you can find the source of arrayStringR(double[] data)

Description

array String R

License

Open Source License

Declaration

public static String arrayStringR(double[] data) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static String arrayStringR(double[] data) {
        if (data == null)
            return null;
        StringBuffer buf = new StringBuffer();
        for (int i = 0; i < data.length; i++) {
            buf.append(round(data[i]) + " ");
        }/*from   ww w.  j  a  v  a2 s .  c  om*/
        return buf.toString();
    }

    public static String arrayStringR(double[][] data) {
        if (data == null)
            return null;
        StringBuffer buf = new StringBuffer();
        for (int i = 0; i < data.length; i++) {
            for (int j = 0; j < data[i].length; j++) {
                buf.append(round(data[i][j], 2) + " ");
            }
            buf.append("\n");
        }
        return buf.toString();
    }

    public static String arrayStringR(float[][] data) {
        if (data == null)
            return null;
        StringBuffer buf = new StringBuffer();
        for (int i = 0; i < data.length; i++) {
            for (int j = 0; j < data[i].length; j++) {
                buf.append(round(data[i][j], 2) + " ");
            }
            buf.append("\n");
        }
        return buf.toString();
    }

    /** Rounds the number to 4 significant digits */
    public static double round(double d) {
        if (d == 0.0)
            return d;
        int digits = (int) (Math.log(d) / Math.log(10));
        return round(d, 3 - digits);
    }

    /** Rounds the number to n decimal places */
    public static double round(double d, int n) {
        double shift = Math.pow(10, n);
        return ((double) ((long) (d * shift + 0.5))) / shift;
    }
}

Related

  1. arraysConvert(String[] src, int column)
  2. arraySeekDelete(final T[] arr, final T[] dest, final T... dels)
  3. arrayStr(int[] A)
  4. arrayString(double[] test)
  5. arrayString(int[] data)
  6. arrayTransfer(int[] ids)
  7. arrayType(String type)
  8. arrayTypeToZeroLengthArray(String arrayType)
  9. arrayUnEscape(String string)