Convert Number to Real

Asked

Viewed 566 times

1

I’m looking to develop an example Simulator: from 1 real to 99 real he multiplies by X10 and above 100 real he multiplies by X11.

I was wondering how you convert the campo1 for real when typing?

Code:

<html>
   <body>
       <head>

       </head>
<script> 
function soma() 
{
form.campo4.value = (form.campo1.value*1) * (form.campo2.value*1)
$('form.campo1').priceFormat({
    prefix: 'R$ ',
    centsSeparator: ',',
    thousandsSeparator: '.'
});
}
</script>
<form name="form">
    <p> Simulador de Cash's</p>
<input name="campo1" type="text" value="" class="soma"><br> 
<input name="campo2" value="22" readonly><br> 
<input name="campo4" readonly><br>
<input type="button" onclick="soma()" value="CALCULAR">
</form>
 </body>
</html>
  • Depends, what would be the monetary value of the campo1?

2 answers

2


I suggest a jQuery plugin called maskMoney (download here). It adds coin mask in the field you specify.

To use it, click on your page with:

<script src="jquery.maskMoney.js" type="text/javascript"></script>

And call the plugin with the script:

$(function(){
 $("input").maskMoney({symbol:'R$ ', 
showSymbol:false, thousands:'.', decimal:',', symbolStay: true});
 });

A nice tutorial on how to use the plugin.

Fiddle for testing.

  • Thank you <3 It helped me a lot God bless you

0

it worked here the most link when I will multiply ta giving Nan because :?

<html>
   <body>
   <script src="jquery.min.js" type="text/javascript"></script>
    <script src="jquery.maskMoney.js" type="text/javascript"></script>
<script> 
function soma() 
{
form.campo4.value = (form.campo1.value*1) * (form.campo2.value*1) 
}
</script>
<script type="text/javascript">
$(function(){
 $("#demo4").maskMoney({symbol:'R$ ', 
showSymbol:true, thousands:'.', decimal:',', symbolStay: true});
 })
</script>
<form name="form">
<input name="campo1" id="demo4"><br> 
<input name="campo2" value="22" id="demo3"><br>  
<input name="campo4" readonly><br>
<input type="button" onclick="soma()" value="Soma os Valores">
</form>
   </body>
</html>

then the code tests on your machine for you to see

Browser other questions tagged

You are not signed in. Login or sign up in order to post.