Problema con decimales

HOLA K TAL, TENGO UN PROBLEMA K ME ESTA VOLVIENDO LOCO,INTENTO METER EN UNA BASE DE DATOS MICROSOFT ACCESS UN CAMPO CON 2 DECIMALES E.J.(6.123,12)
Y LO METO TODO Y LOS DECIMALES NO ME ENTRAN:
DIM IMPORTE AS DOUBLE
IMPORTE = Val(TXTIMP)
SQL = "insert into cobros (cliente,fecha,vto,importe,nf,zona,proveedor)" & " Values " & "('" & cmbcli.Text & "' " & "," & "'" & fec & "'" & "," & "'" & VTO & "'" & "," & IMPORTE & "," & Numfac & "," & "'" & CMBZON.Text & "'" & "," & "'" & CMBPRO.Text & "'" & ")"
con.Execute SQL
EN LA BASE DE DATOS, EL TIPO DE DATO ES NUMERO DOBLE, PROBE A USAR DE MOLDE EN VEZ DE UN VAL, EL DE LOS DOBLES Y ME DA ERROR....AYUDA!!!
Respuesta
1
El error esta en que estas metiendole a la variable real IMPORTE un valor val. El codigo debe ser:
IMPORTE = cdbl(TXTIMP)
Con esto se debe de solucionar.
Saludos.
Eh.
La notacion para un valor real debe ser sin comas, solo punto, ej.
6123.12
El numero de ejemplo que estas usando es incorrecto
6.123,12
Utiliza la funcion que te acabo de dar, esta si funciona.
Saludos.
Eh.
No olvides finalizar la respuesta.
Con este debe de funcionarte a la perfeccion, esta funcion es para dar formato al numero real y entonces si se lo mandas a tu variable IMPORTE:
FormatNumber Function
See Also Example Specifics
Description
Returns an expression formatted as a number.
Syntax
FormatNumber(Expression[,NumDigitsAfterDecimal [,IncludeLeadingDigit [,UseParensForNegativeNumbers [,GroupDigits]]]])
The FormatNumber function syntax has these parts:
Part Description
Expression Required. Expression to be formatted.
NumDigitsAfterDecimal Optional. Numeric value indicating how many places to the right of the decimal are displayed. Default value is 1, which indicates that the computer's regional settings are used.
IncludeLeadingDigit Optional. Tristate constant that indicates whether or not a leading zero is displayed for fractional values. See Settings section for values.
UseParensForNegativeNumbers Optional. Tristate constant that indicates whether or not to place negative values within parentheses. See Settings section for values.
GroupDigits Optional. Tristate constant that indicates whether or not numbers are grouped using the group delimiter specified in the computer's regional settings. See Settings section for values.
Settings
The IncludeLeadingDigit, UseParensForNegativeNumbers, and GroupDigits arguments have the following settings:
Constant Value Description
vbTrue 1 True
vbFalse 0 False
VbUseDefault 2 Use the setting from the computer's regional settings.
Remarks
When one or more optional arguments are omitted, the values for omitted arguments are provided by the computer's regional settings.
Note All settings information comes from the Regional Settings Number tab.
pues en serio pongo 12.35
y me lo pasa a 1235
gracias chao
Hago lo que me dices, y al hacer esto:
IMPORTE= cdbl(txtimp)
pongo por ejemplo 12.32 y me lo pasa
a 1232
que pasa aqui?????
muchas gracias por tu ayuda
la hice asi:
Importe = FormatNumber(TXTIMP, 2, vbTrue, vbTrue, vbTrue)
y meto por ejemplo:
12.35 y me la transforma en: 1.235,00
Se me esta ocurriendo que tu configuracion regional es la que esta afectando, ¿la tienes configurada en configuracion de españa? ¿O cuál?
ESPAÑA ALFABETIZACION TRADICIONAL
gracias por todo y lo siento por el coñazo pero no funciona...
Gracias
Se me hace super extraño, algo hay que no esta funcionando bien, creo que a distancia es dificil resolver este tipo de problemas que no se solucionan mas que intentando de muchas formas. Lo siento por no tenerte la solucion.
Saludos.
Eh.
No olvides finalizar la respuesta.

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas