package cnp.ew.converter;

import java.util.*;

class CpScientificNotationToString implements CpToStringConverter
{

    public boolean showPositiveExponentSign;

    public String scientificNotationCharacterString="e";

    CpDecimalToString exponentConverter;

    public void setExponentFormatString(String exponentFormatString)
    {
        exponentConverter = new CpDecimalToString(exponentFormatString);
    }

    public String convert(Object o)
    {

        double decimalPart = ((Number)o).doubleValue();
        int exponent = 0;
        String string;

        while (decimalPart >= 10) {
            decimalPart /= 10;
            exponent++;
        }
        while (decimalPart < 1) {
            decimalPart *= 10;
            exponent--;
        }

        string = scientificNotationCharacterString;
        if (exponent < 0) {
            string = string + "-";
        } else {
            if (showPositiveExponentSign) {
                string = string + "+";
            }
        }

        return string + exponentConverter.convert(new Integer(Math.abs(exponent)));
    }

    public void setFormatString(String s)
    {
    }
}
