Jump to content


Photo

Formatação De 6 Casas Decimais


  • Faça o login para participar
7 replies to this topic

#1 Hambonso

Hambonso

    12 Horas

  • Usuários
  • 124 posts
  • Sexo:Não informado

Posted 08/05/2010, 13:25

Eu estou readaptando uma função que formata valores em moeda, para que possa ser inserido no banco, valores com 6 casas decimais. Mas estou tendo problemas, quando o valor digitado for maior que 999,999999. A função funciona perfeitamente quando são digitados valores menores que 1.000, mas igual ou maior que esse valor, a função deixa de formata com 6 casas decimais e passa a formatar com 5 casas decimais. Segue o código a baixo:

A FUNÇÂO:
function Formata(campo,tammax,teclapres,decimal) {
var tecla = teclapres.keyCode;
vr = Limpar(campo.value,"0123456789");
tam = vr.length;
dec=decimal

if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }

if (tecla == 8 )
{ tam = tam - 1 ; }

if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 )
{

if ( tam <= dec )
{ campo.value = vr ; }

if ( (tam > dec) && (tam <= 9) ){
campo.value = vr.substr( 0, tam - 6 ) + "," + vr.substr( tam - 6, tam ) ; }
if ( (tam >= 10) && (tam <= 12) ){
campo.value = vr.substr( 0, tam - 9 ) + "." + vr.substr( tam - 9, 3 ) + "," + vr.substr( tam - 6, tam ) ;}
if ( (tam >= 13) && (tam <= 15) ){
campo.value = vr.substr( 0, tam - 12 ) + "." + vr.substr( tam - 12, 3 ) + "." + vr.substr( tam - 9, 3 ) + "," + vr.substr( tam - 6, tam ) ; }
if ( (tam >= 16) && (tam <= 18) ){
campo.value = vr.substr( 0, tam - 15 ) + "." + vr.substr( tam - 15, 3 ) + "." + vr.substr( tam - 12, 3 ) + "." + vr.substr( tam - 9, 3 ) + "," + vr.substr( tam - 6, tam ) ; }
if ( (tam >= 19) && (tam <= 21) ){
campo.value = vr.substr( 0, tam - 18 ) + "." + vr.substr( tam - 18, 3 ) + "." + vr.substr( tam - 15, 3 ) + "." + vr.substr( tam - 12, 3 ) + "." + vr.substr( tam - 9, 3 ) + "," + vr.substr( tam - 6, tam ) ;}
}

}

No FORM
<td>&nbsp;<input type="text" name="vlcota" maxlength="20" onKeydown="Formata(this,20,event,6)" style='text-align:right; border:1px solid black; font-size:9pt; font-weight:bold; color: #000088; width:120px; height:20px;'>&nbsp;<font face="Arial" size="-6" color="#000009"><b>Valor máximo: 9.999.999,999999</b></font></td>

O que está errado no código da função que está causando esse erro na formatação durante a digitação ?

Desde já agradeço pela atenção.

#2 pyro3x

pyro3x

    E

  • Usuários
  • 201 posts
  • Sexo:Masculino

Posted 09/05/2010, 15:14

Acho que você postou no lugar errado.


Se for PHP, basta você utilizar a função number_format .

Exemplo:
$Valor = "9999999999";


echo number_format($Valor,2,',','.');

Isso vai te retornar: 9.999.999.999,00


Se for javascript que você quer, sugiro que insira um post la. Abraços.



Te ajudei? Que tal me seguir? @eduardostuart

Edição feita por: pyro3x, 09/05/2010, 15:15.


#3 André Manoel

André Manoel

    Doutor

  • Usuários
  • 996 posts
  • Sexo:Masculino
  • Localidade:Brasilia

Posted 10/05/2010, 09:29

Movendo o tópico para o local correto.
Quando for postar verifique qual é a sua dúvida e em qual parte do fórum específica a dúvida se encaixa.
Iniciando na Ajuda On line...

Posted Image Meu post lhe ajudou? Reputar/votar é uma das formas de agradecer.

#4 Hambonso

Hambonso

    12 Horas

  • Usuários
  • 124 posts
  • Sexo:Não informado

Posted 11/05/2010, 16:38

Pyro3x, do jeito que vc colocou, usando o format_number, é usado para uma formatação fixa, o que eu preciso é que a formatação seja feita durante a digitação do valor.

Edição feita por: Hambonso, 11/05/2010, 16:39.


#5 LarPhozyHah

LarPhozyHah

    Super Veterano

  • Usuários
  • 14515 posts
  • Sexo:Masculino
  • Localidade:San Miguel de Tucuman

Posted 16/09/2017, 06:47

Zithromax Azithromycin Tablets generic cialis Cialis Ayuda Durar Mas
Over The Counter Amoxicillin Generika Cialis Oral Jelly Buy Viagra Canadian No Prescription
Efecto Kamagra <a href=http://cialtobuy.com>cialis buy online</a> Xenical
Buy Amitriptyline Online Uk buy cialis Levitra Kaufen 10mg
Mebendazole Over The Counter Cheapeast Stendra On Line
Precios Cialis 10 <a href=http://cialtobuy.com>buy cialis</a> Rio Rico Pharmacy
Buy now isotretinoin claravis cheap cialis Viagra Without Prescription 400 Mg
Where Can I Get Nolvadex
Prescription Sildenafil Citrate <a href=http://cialtobuy.com>cialis buy online</a> Use Propecia Finasteride

#6 LarPhozyHah

LarPhozyHah

    Super Veterano

  • Usuários
  • 14515 posts
  • Sexo:Masculino
  • Localidade:San Miguel de Tucuman

Posted 26/09/2017, 06:18

Online Propecia Cost Cialis Fast Delivery In 3 Days Propecia 2 Gunde Bir cialis Bactrim Antibiotic Buy Online Cialis Remboursement Datos De Propecia

#7 LarPhozyHah

LarPhozyHah

    Super Veterano

  • Usuários
  • 14515 posts
  • Sexo:Masculino
  • Localidade:San Miguel de Tucuman

Posted 05/10/2017, 08:09

Cialis Und Poppers Cephalexin For Horses generic viagra Buy Cialis Online Nopw
Keflex And Vaginitis online pharmacy Dutasteride Where To Buy No Doctor Quick Shipping What Do You Use Amoxicillin For Zithromax 500 Mg
for sale isotretinoin acutane pills pharmacy with free shipping Cheap Secure Doryx Microdox Viagra Krankenkasse Kosten viagra Viagra Achat En Suisse En Asnieres Buy Cheap Plavix

#8 LarPhozyHah

LarPhozyHah

    Super Veterano

  • Usuários
  • 14515 posts
  • Sexo:Masculino
  • Localidade:San Miguel de Tucuman

Posted 22/11/2017, 11:20

Amoxicillin And Sushi Cialis 5mg Online Bestellen Discount On Line Isotretinoin cialis Viagra Zurich Kaufen Where To Buy Alli Weight Loss Pills
24 Hour Candian Pramcy viagra 20 Mg Cialis Side Effects Cialis By Mail
Strep Symptoms Even After Taking Amoxicillin viagra Purchase Cialis Effetti Del Viagra




0 user(s) are reading this topic

0 membro(s), 0 visitante(s) e 0 membros anônimo(s)

IPB Skin By Virteq