private void PrintDouble(StringBuilder sb, double d)
{
char bclFormatFlag;
int precision;
switch ( _conversion )
{
case ConversionAux.Scientific:
// TODO: Decide if we want to make this match the number of digits in the exponent.
// The java version uses two digits. This flag uses three.
// We could get rid of the extra leading 0 in the exponent if necessary
bclFormatFlag = 'e';
precision = _precision == -1 ? 6 : _precision;
break;
case ConversionAux.DecimalFloat:
bclFormatFlag = 'f';
precision = _precision == -1 ? 6 : _precision;
if ((_flags & FormatFlags.Group) != 0)
bclFormatFlag = 'n';
break;
case ConversionAux.General:
// TODO: Implement grouping for General Float.
// This would require detecting the Fixed/Float split and
// switching to N format if fixed range and grouping.
bclFormatFlag = 'g';
precision = _precision == -1 ? 6 : _precision == 0 ? 1 : _precision;
break;
case ConversionAux.HexFloat:
// TODO: Implement HexFloat.
throw new NotSupportedException("HexFloat conversion not supported (yet)");
default:
throw Util.UnreachableCode();
}
if ((_flags & FormatFlags.UpperCase) != 0)
bclFormatFlag = Char.ToUpper(bclFormatFlag);
string bclFormat = String.Format("{0}{1}", bclFormatFlag, precision);
string val = Math.Abs(d).ToString(bclFormat);
bool isNeg = d < 0.0;
StringBuilder sb1 = new StringBuilder();
PrintLeadingSign(sb1,isNeg);
PrintMagnitude(sb1, isNeg, val);
PrintTrailingSign(sb1, isNeg);
PrintWithJustification(sb, sb1.ToString());
}