Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Ilano

Inserção de números decimais

Recommended Posts

Olá pessoal,

 

Como faço para fazer inclusões em banco de dados SQLServer de valores com 2 ou 3 casas decimais?

 

Estou tentando fazer da seguinte forma:

 

...

SQL.Append("INSERT INTO (Det_Codigo, Ped_Codigo, Det_Quantidade, Pro_Codigo, Det_Unitatio, Det_Desconto, Det_Total, Ud_Codigo) VALUES (" )

SQL.Append(LbCodigo.Text & ", " & LbPedido.Text & "," & CDbl(TxtQuantidade.Text) & ", ")

SQL.Append(DDLProdutos.SelectedValue & ", " & CDbl(TxtUnitario.Text) & ", ")

SQL.Append(CDbl(TxtDesconto.Text) & ", " & CDbl(TxtTotal.Text) & ", " & DDLUnidade.SelectedValue)

...

Onde os campos TxtQuantidade tem 3 casas decimais e os campos TxtUnitario, TxtDesconto e TxtTotal têm 2 casa decimais.

 

Grato pela ajuda!

Compartilhar este post


Link para o post
Compartilhar em outros sites

Isso mesmo!

Vamos supor q os campos abaixo trarão os respectivos valores:

 

LbCodigo.Text = 1

LbPedido.Text = 1

TxtQuantidade.Text = 2,000

DDLProdutos.SelectedValue = 2

TxtUnitario.Text = 25,52

TxtDesconto.Text = 0,00

TxtTotal.Text = 51,40

DDLUnidade.SelectedValue = UND

 

Preciso fazer a inclusão destes valores, mas não estou conseguindo.

Será necessário fazer uma conversão?

Compartilhar este post


Link para o post
Compartilhar em outros sites

Não.

 

você está utilizando vírgula.

tente fazer assim:

LbCodigo.Text = 1LbPedido.Text = 1TxtQuantidade.Text = 2.000DDLProdutos.SelectedValue = 2TxtUnitario.Text = 25.52TxtDesconto.Text = 0.00TxtTotal.Text = 51.40DDLUnidade.SelectedValue = UND

Use ponto para determinar os valores decimais.

 

Com a vírgula.O Compilador não vai interpretar como um valor de ponto flutuante(double).

Compartilhar este post


Link para o post
Compartilhar em outros sites

Encontrei o arquivo *.js abaixo para formatar moeda. Como utilizo ele?

function MascaraValorMoeda(fld, e) { var milSep = "."; var decSep = ","; var sep = 0; var key = ''; var i = j = 0; var len = len2 = 0; var strCheck = '0123456789'; var aux = aux2 = ''; var whichCode = (window.Event) ? e.which : e.keyCode; if (whichCode == 13) return true; key = String.fromCharCode(whichCode); if (strCheck.indexOf(key) == -1) return false; len = fld.value.length; for (i = 0; i < len; i++) if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) break; aux = ''; for (; i < len; i++) if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i); aux += key; len = aux.length; if (len == 0) fld.value = ''; if (len == 1) fld.value = '0'+ decSep + '0' + aux; if (len == 2) fld.value = '0'+ decSep + aux; if (len > 2){ aux2 = ''; for (j = 0, i = len - 3; i >= 0; i--){ if (j == 3){ aux2 += milSep; j = 0; } aux2 += aux.charAt(i); j++; } fld.value = ''; len2 = aux2.length; for (i = len2 - 1; i >= 0; i--) fld.value += aux2.charAt(i); fld.value += decSep + aux.substr(len - 2, len); } return false; }

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.