public static String representMatrix(double[][] matrix, int decimalPlaces) {

		if (matrix == null) {

			return "null";

		}

		int longest = 0;

		List<List<String>> values = new LinkedList<List<String>>();

		int rows = matrix.length;

		for (int row = 0; row < rows; row++) {

			List<String> rowValues = new LinkedList<String>();

			double[] currentRow = matrix[row];

			if (currentRow == null) {

				rowValues.add(" null");

				if (longest < 5) {

					// ensure that the padding is set to the length of the
					// longest represented value
					longest = 5;

				}

			} else {

				int columns = currentRow.length;

				for (int column = 0; column < columns; column++) {

					// do not perform null check on value because java does not
					// allow the assignment of null to primitives

					double value = currentRow[column];

					String rounded = new BigDecimal(value)
							.divide(BigDecimal.ONE, decimalPlaces,
									RoundingMode.HALF_EVEN)
							.stripTrailingZeros().toPlainString();

					rounded = rationaliseRepresentation(rounded);

					if (value >= 0d) {

						// shift positive values one space to the right in order
						// to align digits with other digits and not with any
						// minus sign
						rounded = " " + rounded;

					}

					int length = rounded.length();

					if (length > longest) {

						// ensure that the padding is set to the length of the
						// longest represented value
						longest = length;

					}

					rowValues.add(rounded);

				}

			}

			values.add(rowValues);

		}

		StringBuilder representation = new StringBuilder();

		int rowsLastIndex = rows - 1;

		for (int row = 0; row < rows; row++) {

			List<String> rowValues = values.get(row);

			int columns = rowValues.size();

			int columnsLastIndex = rowValues.size() - 1;

			for (int column = 0; column < columns; column++) {

				String value = rowValues.get(column);

				representation.append(value);

				if (column < columnsLastIndex) {

					int length = value.length();

					int difference = longest - length;

					// add an extra space to separate values
					difference++;

					StringBuilder spaces = new StringBuilder();

					for (int space = 0; space < difference; space++) {

						spaces.append(' ');

					}

					representation.append(spaces);

				}

			}

			if (row < rowsLastIndex) {

				representation.append(NEWLINE);

			}

		}

		return representation.toString();

	}