20^20 = overflow

10/10/2005 - 17:43 por Ch0rY | Informe spam
Como puedo asignar el valor de esa operacion a una variable?

He probado como Decimal, Long, Int64, Integer y me da error de overflow
Si lo asigno a un string me da "1,048576E+26" (¿esto como se llamaba q no me
acuerdo?).

Pos eso como puedo obtener el resultado de la operación.

Gracias

Preguntas similare

Leer las respuestas

#1 Jesús López
10/10/2005 - 20:36 | Informe spam
Utiliza tipo de datos Double.


"Ch0rY" escribió en el mensaje
news:
Como puedo asignar el valor de esa operacion a una variable?

He probado como Decimal, Long, Int64, Integer y me da error de overflow
Si lo asigno a un string me da "1,048576E+26" (¿esto como se llamaba q no
me
acuerdo?).

Pos eso como puedo obtener el resultado de la operación.

Gracias
Respuesta Responder a este mensaje
#2 Eduardo A. Morcillo [MS MVP VB]
11/10/2005 - 05:44 | Informe spam
He probado como Decimal, Long, Int64, Integer y me da error de
overflow



Como Decimal deberia funcionarte. Con Single y Double tambien.

Eduardo A. Morcillo [MS MVP VB]
http://www.mvps.org/emorcillo
http://mvp.support.microsoft.com/pr...4EF5A4191C
Respuesta Responder a este mensaje
#3 Ch0rY
11/10/2005 - 12:20 | Informe spam
Como Decimal sigue sin rular
Como Single me devuelve "Infinito"
Como Double sigue dandome de resultado un valor ¿cientifico?
1.2994262207056124E+262, como puedo representarlo decimal, talcual

Gracias por las respuestas

chory
Respuesta Responder a este mensaje
#4 Juan Pedro Gonzalez
11/10/2005 - 13:46 | Informe spam
Hola Ch0rY,

¿Porque no lo conviertes tu mismo/a?

No he tenido tiempo para comprobar que esta funcion funciones en el 100% de
los casos (si se me ha colado alguno pon el codigo corregido):

Private Function DoubleToString(ByVal numero As Double) As String
Dim oResultado As String = numero.ToString
Dim PosicionDelExponente As Integer = oResultado.IndexOf("E"c)

If PosicionDelExponente > 0 Then
Dim arrValores() As String = oResultado.Split("E"c)
Dim Exponente As Integer = arrValores(1)

arrValores =
arrValores(0).Split(System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator)

If Exponente > 0 Then
Dim sBuilder As New System.Text.StringBuilder(arrValores(0))

If arrValores.Length = 1 Then
sBuilder.Append("0", Exponente)
Else
If Exponente > arrValores(1).Length Then
sBuilder.Append(arrValores(1))
sBuilder.Append("0", Exponente - arrValores(1).Length)
Else
sBuilder.Append(arrValores(1).Substring(0, Exponente))
sBuilder.Append(System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator)
sBuilder.Append(arrValores(1).Substring(Exponente))
End If
End If

oResultado = sBuilder.ToString
Else
Dim sBuilder As New System.Text.StringBuilder()
Exponente = Exponente * -1

If Exponente > arrValores(0).Length Then
Exponente -= arrValores(0).Length
sBuilder.Append("0"c)
sBuilder.Append(System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator)
sBuilder.Append("0", Exponente)
sBuilder.Append(arrValores(0))
If arrValores.Length > 1 Then
sBuilder.Append(arrValores(1))
End If
Else
sBuilder.Append(arrValores(0).Substring(0,
arrValores(0).Length - Exponente))
sBuilder.Append(System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator)
sBuilder.Append(arrValores(0).Substring(arrValores(0).Length
- Exponente))
If arrValores.Length > 1 Then
sBuilder.Append(arrValores(1))
End If
End If

oResultado = sBuilder.ToString
End If

End If

Return oResultado
End Function

Tambien podrias crear tu propia clase a partir del tipo Double y sobrecarga
el ToString con esta funcion para que siempre muestre el numero completo.

Espero que sea lo que andas buscando.

Un saludo,

Juan Pedro González
Respuesta Responder a este mensaje
#5 Guillermo guille
11/10/2005 - 15:19 | Informe spam
prueba convirtiendo la expresión en decimal:
Sub Main()

Dim de As Decimal

Dim dbl As Double

de = CDec(20 ^ 20)

dbl = 20 ^ 20

Console.WriteLine("20 ^20 ={0}Decimal: {1}{0}Double : {2}", vbCrLf, de, dbl)

Console.ReadLine()

End Sub



Nos vemos.
Guillermo
Microsoft VB MVP desde 1997
Mentor Asociado de Solid Quality Learning Iberoamericana

¡Vuelven los foros del Guille!
(en pruebas, pero vuelven)
http://test.foros.elguille.info/

"Ch0rY" escribió en el mensaje
news:
Como Decimal sigue sin rular
Como Single me devuelve "Infinito"
Como Double sigue dandome de resultado un valor ¿cientifico?
1.2994262207056124E+262, como puedo representarlo decimal, talcual

Gracias por las respuestas

chory
Respuesta Responder a este mensaje
Ads by Google
Help Hacer una preguntaSiguiente Respuesta Tengo una respuesta
Search Busqueda sugerida