Ir para conteúdo

Arquivado

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

fevalini

Formatar casas decimais em asp

Recommended Posts

Olá pessoal do forum.... bem, primeiramente gostaria de agradecer a todos os amigos que sempre tem algo a oferecer para os menos sabidos em programação, frequentadores deste forum, como eu.

 

Estou com um problema que me parece até fácil de se resolver, porém lí algumas apostilas, tutos, e tópicos neste mesmo forum, mas sem sucesso.

 

Tenho um página que retorna valores vindos do bd, e um formulário que recebe dois parâmetros, valor X quantidade, oque eu não consigo de jeito nenhum é encontrar a melhor maneira de se limitar o números de casas decimas após a vírgula...

 

Se algum amigo puder dar uma luz, fico imensamente agradecido.

 

 

CODE
<script language="javascript">

function Calcula(){

var Parametro1=document.frm.valor.value.replace(",",".");;

var Parametro2=document.frm.quantidade.value.replace(",",".");;

var Soma=((parseFloat(Parametro1))*(parseFloat(Parametro2)));

document.frm.total.value=Soma;

}

</script>

 

 

CODE
<form name="frm">

<input name="valor" type="text" value="<%=(detalhe.Fields.Item("valor").Value)%>">

<BR>

<input name="quantidade" type="text" value="<%=(detalhe.Fields.Item("quantidade").Value)%>">

<BR><BR>

<input type="text" name="total"><BR><BR>

 

<input type="button" value="Calcula" onClick="Calcula()">

 

</form>

Compartilhar este post


Link para o post
Compartilhar em outros sites

Opa! Onde está a dúvida de ASP?

 

Você postou apenas Javascript. Somente os valores estão vindo através do ASP.

 

Esclareça melhor sua dúvida, caso contrário terei que mover o tópico para o fórum de Javascript.

Compartilhar este post


Link para o post
Compartilhar em outros sites

Desculpa por postar no lugar errado... eu ainda aprendo!!!

 

Mas de qualquer forma... fuçando e lendo muito - consegui achar a solução no forum da ABRAWEB.

Então vou compartilhar a solução aqui com todos os amigos do forum Imasters:

 

É só usar isto aqui na sua variável que recebe o valor... no meu caso a variável "soma"

 

 

soma.toFixed(2)

 

abração a todos...

Compartilhar este post


Link para o post
Compartilhar em outros sites

Bem galera... tô eu aqui novamente...

 

Meus problemas ainda não se esgotaram com o que postei acima, resolvi metade do meu problema...

Porém quanto fui testar a página não percebi o script só funcionava quanto só tem um registro retornando no bd, mas quanto tem mais registros não funciona, agora minha dúvida é será que o problema tá no asp ou no javascript?

 

Abaixo está o código completo... se algum puder de novo dar uma olhada, eu agradeço muito...

 

Valeu !!!

 

CODE
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>

<!--#include file="../Connections/dbconstru.asp" -->

<%

Dim MM_editAction

MM_editAction = CStr(Request.ServerVariables("SCRIPT_NAME"))

If (Request.QueryString <> "") Then

MM_editAction = MM_editAction & "?" & Server.HTMLEncode(Request.QueryString)

End If

 

' boolean to abort record edit

Dim MM_abortEdit

MM_abortEdit = false

%>

<%

' *** Delete Record: construct a sql delete statement and execute it

 

If (CStr(Request("MM_delete")) = "form1" And CStr(Request("MM_recordId")) <> "") Then

 

If (Not MM_abortEdit) Then

' execute the delete

Set MM_editCmd = Server.CreateObject ("ADODB.Command")

MM_editCmd.ActiveConnection = MM_dbconstru_STRING

MM_editCmd.CommandText = "DELETE FROM orcamento WHERE idorcamento = ?"

MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param1", 5, 1, -1, Request.Form("MM_recordId")) ' adDouble

MM_editCmd.Execute

MM_editCmd.ActiveConnection.Close

 

' append the query string to the redirect URL

Dim MM_editRedirectUrl

MM_editRedirectUrl = "clientes.asp"

If (Request.QueryString <> "") Then

If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0) Then

MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString

Else

MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString

End If

End If

Response.Redirect(MM_editRedirectUrl)

End If

 

End If

%>

<%

Dim detalhe__MMColParam

detalhe__MMColParam = "1"

If (Request.QueryString("idcliente") <> "") Then

detalhe__MMColParam = Request.QueryString("idcliente")

End If

%>

<%

Dim detalhe

Dim detalhe_cmd

Dim detalhe_numRows

 

Set detalhe_cmd = Server.CreateObject ("ADODB.Command")

detalhe_cmd.ActiveConnection = MM_dbconstru_STRING

detalhe_cmd.CommandText = "SELECT orcamento.*, cliente.* FROM orcamento, cliente WHERE idcliente = ? and orcamento.fkcliente = cliente.login"

detalhe_cmd.Prepared = true

detalhe_cmd.Parameters.Append detalhe_cmd.CreateParameter("param1", 200, 1, 50, detalhe__MMColParam) ' adVarChar

 

Set detalhe = detalhe_cmd.Execute

detalhe_numRows = 0

%>

<%

Dim Repeat1__numRows

Dim Repeat1__index

 

Repeat1__numRows = -1

Repeat1__index = 0

detalhe_numRows = detalhe_numRows + Repeat1__numRows

%>

<%

' *** Recordset Stats, Move To Record, and Go To Record: declare stats variables

 

Dim detalhe_total

Dim detalhe_first

Dim detalhe_last

 

' set the record count

detalhe_total = detalhe.RecordCount

 

' set the number of rows displayed on this page

If (detalhe_numRows < 0) Then

detalhe_numRows = detalhe_total

Elseif (detalhe_numRows = 0) Then

detalhe_numRows = 1

End If

 

' set the first and last displayed record

detalhe_first = 1

detalhe_last = detalhe_first + detalhe_numRows - 1

 

' if we have the correct record count, check the other stats

If (detalhe_total <> -1) Then

If (detalhe_first > detalhe_total) Then

detalhe_first = detalhe_total

End If

If (detalhe_last > detalhe_total) Then

detalhe_last = detalhe_total

End If

If (detalhe_numRows > detalhe_total) Then

detalhe_numRows = detalhe_total

End If

End If

%>

 

<%

' *** Recordset Stats: if we don't know the record count, manually count them

 

If (detalhe_total = -1) Then

 

' count the total records by iterating through the recordset

detalhe_total=0

While (Not detalhe.EOF)

detalhe_total = detalhe_total + 1

detalhe.MoveNext

Wend

 

' reset the cursor to the beginning

If (detalhe.CursorType > 0) Then

detalhe.MoveFirst

Else

detalhe.Requery

End If

 

' set the number of rows displayed on this page

If (detalhe_numRows < 0 Or detalhe_numRows > detalhe_total) Then

detalhe_numRows = detalhe_total

End If

 

' set the first and last displayed record

detalhe_first = 1

detalhe_last = detalhe_first + detalhe_numRows - 1

 

If (detalhe_first > detalhe_total) Then

detalhe_first = detalhe_total

End If

If (detalhe_last > detalhe_total) Then

detalhe_last = detalhe_total

End If

 

End If

%>

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<script language="javascript">

function Calcula(){

var Parametro1=document.frm.valor.value.replace(",",".");;

var Parametro2=document.frm.quantidade.value.replace(",",".");;

var Soma=((parseFloat(Parametro1))*(parseFloat(Parametro2)));

document.frm.total.value=Soma.toFixed(2).replace(".",",");

var Soma=0

}

</script>

 

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Untitled Document</title>

<link href="../cm.css" rel="stylesheet" type="text/css" />

<style type="text/css">

<!--

body {

background-color: #FFFFCC;

margin-top: 0px;

}

-->

</style></head>

 

<body>

<table align="center" bgcolor="#FFFFFF">

<tr>

<td class="ma1h"><div align="center">

<p> </p>

<p>Orçamento para Cliente</p>

<p> </p>

</div></td>

</tr>

<tr>

<td><table align="center">

<tr>

<td class="me1"><div align="center"><span class="me1bb">Nome</span>: <%=(detalhe.Fields.Item("nomecliente").Value)%> | <span class="me1bb">Login</span>:<%=(detalhe.Fields.Item("fkcliente").Value)%> | <span class="me1v">ID Cliente</span>: <%=(detalhe.Fields.Item("idcliente").Value)%> | <span class="me1bb">E-mail</span>: <%=(detalhe.Fields.Item("email").Value)%><br />

</div></td>

</tr>

<tr>

<td class="me1"><div align="center"><span class="me1bb">Cidade</span>: <%=(detalhe.Fields.Item("cidade").Value)%> | <span class="me1bb">Telefone</span>: <%=(detalhe.Fields.Item("telefone").Value)%></div></td>

</tr>

<tr>

<td><table border="1">

<tr>

<td class="me1bv">Número</td>

<td class="me1bv">Produto</td>

<td class="me1bv">Cód. Loja</td>

<td class="me1bv"><div align="center">Valor Unit</div></td>

<td class="me1bv"><div align="center">Qtde.</div></td>

<td class="me1bv"><div align="center">Unid.</div></td>

<td class="me1bv">Data / Hora</td>

<td class="me1bv">Excluir</td>

</tr>

<% While ((Repeat1__numRows <> 0) AND (NOT detalhe.EOF)) %>

<tr>

<td class="fo1l"><%=(detalhe.Fields.Item("idorcamento").Value)%></td>

<td width="150" class="fo1l"><%=(detalhe.Fields.Item("produto").Value)%></td>

<td class="fo1l"><%=(detalhe.Fields.Item("idloja").Value)%></td>

<td width="300" class="fo1l"><div align="center">

 

<form name="frm">

<input name="valor" type="text" value="<%=(detalhe.Fields.Item("valor").Value)%>" size="10">

<input name="quantidade" type="text" value="<%=(detalhe.Fields.Item("quantidade").Value)%>" size="5">

<input name="total" type="text" size="10">

<input type="button" value="OK" onClick="Calcula()">

 

</form>

<label></label>

</div></td>

<td class="fo1l"><div align="center"><%=(detalhe.Fields.Item("quantidade").Value)%></div></td>

<td class="fo1l"><div align="center"><%=(detalhe.Fields.Item("unidade").Value)%></div></td>

<td class="fo1l"><%=(detalhe.Fields.Item("data").Value)%></td>

<td class="fo1l"><form id="form1" name="form1" method="post" action="<%=MM_editAction%>">

<label>

<input type="submit" name="button" id="button" value="Del" />

</label>

<input type="hidden" name="MM_delete" value="form1" />

<input type="hidden" name="MM_recordId" value="<%= detalhe.Fields.Item("idorcamento").Value %>" />

</form></td>

</tr>

<%

Repeat1__index=Repeat1__index+1

Repeat1__numRows=Repeat1__numRows-1

detalhe.MoveNext()

Wend

%>

</table></td>

</tr>

<tr>

<td> </td>

</tr>

<tr>

<td class="me1v">Total: <%=(detalhe_total)%> Iten(s)</td>

</tr>

</table></td>

</tr>

<tr>

<td> </td>

</tr>

</table>

<p> </p>

</body>

</html>

<%

detalhe.Close()

Set detalhe = Nothing

%>

Compartilhar este post


Link para o post
Compartilhar em outros sites

Olá amigo, eu quero exibir todos os registros que estejam gravados no bd, podeser um só (com um funcionou) ou muitos registros (deu erro, e o cálculo não foi exibibo no textfield total que recebe a variável valor).

 

abração

Compartilhar este post


Link para o post
Compartilhar em outros sites

que erro que da?

 

assim que possivel se livre do codigo gerado pelo DW alem de sujo tem muita inutilidade

Compartilhar este post


Link para o post
Compartilhar em outros sites
if IsNumeric(Valor) then
'Verifica se é formato brasileiro ou americano.
if InStr(Valor, ".") > InStr(Valor, ",") then
Session.LCID = 1033
else
Session.LCID = 1046
end if
Valor= FormatNumber(CDbl(Valor), 2)
else
Valor= FormatNumber(0, 2)
end if

Session.LCID = [Original]

Compartilhar este post


Link para o post
Compartilhar em outros sites

Dê prioridade para responder post mais recentes, por favor. este post é de 2008. Obrigado

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.