vendredi 27 avril 2012

Format real number


A little job to convert a real number to char

public static str numtostr(real _r,int _numberofDecimal=2,str _Format = "")
{
    str num;
    if(!_Format)
        switch(_numberofDecimal)
        {
            case 0: num = System.String::Format("{0:0}", _r); break;
            case 1: num = System.String::Format("{0:0.#}", _r); break;
            case 2: num = System.String::Format("{0:0.##}", _r); break;
            case 3: num = System.String::Format("{0:0.###}", _r); break;
            case 4: num = System.String::Format("{0:0.####}", _r); break;
            case 5: num = System.String::Format("{0:0.#####}", _r); break;
            case 6: num = System.String::Format("{0:0.######}", _r); break;
            case 7: num = System.String::Format("{0:0.#######}", _r); break;
            case 8: num = System.String::Format("{0:0.########}", _r); break;
            case 8: num = System.String::Format("{0:0.#########}", _r); break;
            case 10: num = System.String::Format("{0:0.##########}", _r); break;
        }
    else
        num = System.String::Format(_Format, _r);
    return num;
}

Aucun commentaire:

Enregistrer un commentaire