Tópico anterior Próximo tópico Novo tópico
ASP.NET
#497884 - 23/08/2021 14:31:54 | ||||
![]() RICARDOPIBU CABO FRIO Cadast. em:Março/2018 ![]() |
Última edição em 23/08/2021 14:36:17 por RICARDOPIBU Olá!Estou desde o inicio do ano migrando para Asp.Net Core MVC (ou seja, estou muito recente nesta linguagem), e me deparei com um problema na hora da formatação no campo que leva moeda e peço por gentileza se alguém pode me ajudar! É seguinte, quando estou no ambiente localhost a função abaixo funciona perfeitamente, tanto para versão PC quanto para mobile, porém após publicar minha aplicação ela só funciona na versão PC, e na versão mobile nada acontece com esta função abaixo: function moeda(a, e, r, t) { a.style.backgroundColor = 'white'; let n = '' , h = j = 0 , u = tamanho2 = 0 , l = ajd2 = '' , o = window.Event ? t.which : t.keyCode; if (13 == o || 8 == o) return !0; if (n = String.fromCharCode(o), -1 == '0123456789'.indexOf(n)) return !1; for (u = a.value.length, h = 0; h < u && ('0' == a.value.charAt(h) || a.value.charAt(h) == r); h++) ; for (l = ''; h < u; h++) -1 != '0123456789'.indexOf(a.value.charAt(h)) && (l += a.value.charAt(h)); if (l += n, 0 == (u = l.length) && (a.value = ''), 1 == u && (a.value = '0' + r + '0' + l), 2 == u && (a.value = '0' + r + l), u > 2) { for (ajd2 = '', j = 0, h = u - 3; h >= 0; h--) 3 == j && (ajd2 += e, j = 0), ajd2 += l.charAt(h), j++; for (a.value = '', tamanho2 = ajd2.length, h = tamanho2 - 1; h >= 0; h--) a.value += ajd2.charAt(h); a.value += r + l.substr(u - 2, u) } return !1 } function moeda(a, e, r, t) { a.style.backgroundColor = 'white'; let n = '' , h = j = 0 , u = tamanho2 = 0 , l = ajd2 = '' , o = window.Event ? t.which : t.keyCode; if (13 == o || 8 == o) return !0; if (n = String.fromCharCode(o), -1 == '0123456789'.indexOf(n)) return !1; for (u = a.value.length, h = 0; h < u && ('0' == a.value.charAt(h) || a.value.charAt(h) == r); h++) ; for (l = ''; h < u; h++) -1 != '0123456789'.indexOf(a.value.charAt(h)) && (l += a.value.charAt(h)); if (l += n, 0 == (u = l.length) && (a.value = ''), 1 == u && (a.value = '0' + r + '0' + l), 2 == u && (a.value = '0' + r + l), u > 2) { for (ajd2 = '', j = 0, h = u - 3; h >= 0; h--) 3 == j && (ajd2 += e, j = 0), ajd2 += l.charAt(h), j++; for (a.value = '', tamanho2 = ajd2.length, h = tamanho2 - 1; h >= 0; h--) a.value += ajd2.charAt(h); a.value += r + l.substr(u - 2, u) } return !1 } Cursos de Excel e VB6: cursoexcelvba.com.br |
|||
#497887 - 23/08/2021 15:23:34 | ||||
![]() NILSONTRES SAO PAULO Cadast. em:Março/2012 ![]() |
Última edição em 23/08/2021 15:25:01 por NILSONTRES Eu utilizo uma dessas ai:function formatBR(value) { var formatter = new Intl.NumberFormat('pt-BR', { //style: 'currency', currency: 'BRL', minimumFractionDigits: 2, }); var valor = value var formatado = formatter.format(valor); return formatado } function MoedaBR(value) {//format moeda com valor vindo do banco de dados mysql console.log(value) var formatter = new Intl.NumberFormat('pt-BR', { //style: 'currency', currency: 'BRL', minimumFractionDigits: 2, }); //pega o valor no campo e transforma em float var valor = parseFloat(value) valor = valor.replace('.', '') valor = valor.replace(',', '.') var formatado = formatter.format(valor); return formatado } |
|||
#497889 - 23/08/2021 16:10:21 | ||||
![]() RICARDOPIBU CABO FRIO Cadast. em:Março/2018 ![]() |
Citação: : Eu utilizo uma dessas ai: function formatBR(value) { var formatter = new Intl.NumberFormat('pt-BR', { //style: 'currency', currency: 'BRL', minimumFractionDigits: 2, }); var valor = value var formatado = formatter.format(valor); return formatado } function MoedaBR(value) {//format moeda com valor vindo do banco de dados mysql console.log(value) var formatter = new Intl.NumberFormat('pt-BR', { //style: 'currency', currency: 'BRL', minimumFractionDigits: 2, }); //pega o valor no campo e transforma em float var valor = parseFloat(value) valor = valor.replace('.', '') valor = valor.replace(',', '.') var formatado = formatter.format(valor); return formatado } Desde já agradeço! Mas como eu disse anteriormente, eu ainda estou 'engatinhando' nessa linguagem, daí te pergunto: Como vou chamar essa função pelo input do html já tentei assim: onkeypress='MoedaBR(this.value)' ou onkeypress='formatBR(this.value)' e onkeypress='return(MoedaBR(this,'.',',',event))' ou onkeypress='return(formatBR(this,'.',',',event))' Cursos de Excel e VB6: cursoexcelvba.com.br |
|||
#497890 - 23/08/2021 16:34:40 | ||||
![]() NILSONTRES SAO PAULO Cadast. em:Março/2012 ![]() |
Citação: Como vou chamar essa função pelo input do html O método para a chamada em .net não conheço. |
|||
#497891 - 23/08/2021 16:37:45 | ||||
![]() RICARDOPIBU CABO FRIO Cadast. em:Março/2018 ![]() |
Citação: : Como vou chamar essa função pelo input do html O método para a chamada em .net não conheço. Citação: : Como vou chamar essa função pelo input do html O método para a chamada em .net não conheço. Mesmo assim grato! Talvez alguém saiba e pode completar essa essa resposta! Cursos de Excel e VB6: cursoexcelvba.com.br |
|||
#497895 - 24/08/2021 15:17:49 | ||||
![]() NILSONTRES SAO PAULO Cadast. em:Março/2012 ![]() |
Última edição em 24/08/2021 23:55:12 por NILSONTRES É que utilizo com NODE.JS, mas acredito ser a mesma coisa, um html que chama uma função javascript. tipo, meucampomoeda=MoedaBR(valor) |
|||
Tópico anterior Próximo tópico Novo tópico