/// ------------------------------------------------------
/// SwarmOps - Numeric and heuristic optimization for C#
/// Copyright (C) 2003-2011 Magnus Erik Hvass Pedersen.
/// Please see the file license.txt for license details.
/// SwarmOps on the internet: http://www.Hvass-Labs.org/
/// ------------------------------------------------------
namespace SwarmOps
{
public static partial class Tools
{
///
/// Convert an array of System.double values to a string.
///
/// Array of values to be converted to string.
public static string ArrayToString(double[] x)
{
return ArrayToString(x, 4);
}
///
/// Convert an array of System.double values to a string.
///
/// Array of values to be converted to string.
/// Number of digits for each value.
///
public static string ArrayToString(double[] x, int digits)
{
string s = "{ ";
if (x.Length>0)
{
s += NumberToString(x[0], digits);
for (int i = 1; i < x.Length; i++)
{
s += ", " + NumberToString(x[i], digits);
}
}
s += " }";
return s;
}
///
/// Convert an array of System.double values to a string. Not formatted like a C# array.
///
/// Array of values to be converted to string.
public static string ArrayToStringRaw(double[] x)
{
return ArrayToStringRaw(x, 4);
}
///
/// Convert an array of System.double values to a string. Not formattet like a C# array.
///
/// Array of values to be converted to string.
/// Number of digits for each value.
///
public static string ArrayToStringRaw(double[] x, int digits)
{
string s = "";
for (int i = 0; i < x.Length; i++)
{
s += NumberToString(x[i], digits) + " ";
}
return s;
}
///
/// Convert a double-value to a string, formatted for array output.
///
/// Value to convert.
/// Number of digits.
public static string NumberToString(double x, int digits)
{
return System.Math.Round(x, digits).ToString(_cultureInfo);
}
}
}