コード例 #1
0
ファイル: ValorMag.cs プロジェクト: pokenshin/Desire
        public int CompareTo(object obj)
        {
            if (obj == null)
            {
                return(1);
            }

            ValorMag outroValorMag = obj as ValorMag;

            if (this.Magnitude == outroValorMag.Magnitude)
            {
                if (this.Valor == outroValorMag.Valor)
                {
                    return(0);
                }
                else if (this.Valor > outroValorMag.Valor)
                {
                    return(1);
                }
                else if (this.Valor < outroValorMag.Valor)
                {
                    return(-1);
                }
            }
            if (this.Magnitude > outroValorMag.Magnitude)
            {
                return(1);
            }
            if (this.Magnitude < outroValorMag.Magnitude)
            {
                return(-1);
            }

            return(0);
        }
コード例 #2
0
ファイル: ValorMag.cs プロジェクト: pokenshin/Desire
        public ValorMag(string valorMag)
        {
            Conversor conversor = new Conversor();

            if (valorMag.Contains("m"))
            {
                string[] matriz = valorMag.Split('m');
                this.Valor     = Convert.ToInt32(matriz[0]);
                this.Magnitude = Convert.ToInt32(matriz[1]);
                this.ValorReal = conversor.ValorMagParaString(Convert.ToInt32(matriz[0]), Convert.ToInt32(matriz[1]));
            }
            else
            {
                ValorMag valor = conversor.StringParaValorMag(valorMag);
                this.ValorReal = valorMag;
                this.Valor     = valor.Valor;
                this.Magnitude = valor.Magnitude;
            }
        }
コード例 #3
0
        public ValorMag StringParaValorMag(string numero)
        {
            int      magnitude = 0;
            int      valor     = 0;
            ValorMag resultado = new ValorMag();

            //Se for numero decimal
            if ((numero.Contains(",") || numero.Contains(".")))
            {
                //Se o numero decimal for menor que 10
                if (Convert.ToDecimal(numero) < 10)
                {
                    //Se o numero decimal for maior que 1
                    if (Convert.ToDecimal(numero) > 1)
                    {
                        magnitude = 1;
                        numero    = Convert.ToString(numero[0]) + Convert.ToString(numero[2]);
                        valor     = Convert.ToInt32(numero);
                        resultado = new ValorMag(valor, magnitude);

                        return(resultado);
                    }
                    //Se o numero decimal for menor que 1
                    else
                    {
                        magnitude = 0;

                        if (numero.Contains(","))
                        {
                            numero = numero.Split(',')[1];
                        }
                        else
                        {
                            numero = numero.Split('.')[1];
                        }

                        while (numero[0] == '0')
                        {
                            magnitude = magnitude - 1;
                            numero    = numero.Remove(0, 1);
                        }

                        if (numero.Length > 3)
                        {
                            numero = numero.Remove(2, numero.Length - 2);
                        }

                        valor = Convert.ToInt32(numero);

                        if (valor < 10)
                        {
                            valor = valor * 10;
                        }
                        resultado = new ValorMag(valor, magnitude);

                        return(resultado);
                    }
                }
                //Se o numero decimal for maior que 10, descarta quebrados
                else
                {
                    if (numero.Contains(","))
                    {
                        numero = numero.Split(',')[0];
                    }
                    else
                    {
                        numero = numero.Split('.')[0];
                    }
                }
            }
            //Se for numero inteiro ou decimal maior que 10
            magnitude = Convert.ToInt32(numero.Length);
            if (magnitude > 1)
            {
                valor = Convert.ToInt32(numero.Substring(0, 2));
            }
            else
            {
                valor = Convert.ToInt32(numero + "0");
            }

            resultado = new ValorMag(valor, magnitude);

            return(resultado);
        }