maskMoney (jquery) not displaying value correctly

0

Good afternoon guys, I'm having a problem using the jQuery maskMoney plugin. I am using the following statement before

<div style="float:left; width: 25%">
  <asp:Label ID="Label24" runat="server" Text="Valor Total: "></asp:Label>
  <asp:RequiredFieldValidator ID="rfvValTotalEnsinoSuperior"        runat="server" ErrorMessage="Valor Total: Campo obrigatório."            ControlToValidate="tbValorTotalEnsinoSuperior" Display="Dynamic"  Text="*" ValidationGroup="ParteReembolsoEnsinoSuperior" ForeColor="Red"  SetFocusOnError="True"></asp:RequiredFieldValidator>
  <br />
  <asp:TextBox ID="tbValorTotalEnsinoSuperior" Size="25%" runat="server" MaxLength="100" ReadOnly="True"></asp:TextBox>
  <br /><br />
</div>

$("[id*=tbValorTotalEnsinoSuperior]").maskMoney({ prefix: 'R$ ', thousands: '.', decimal: ',' });

E em minha função tenho:   
    $("[id*=tbValorTotalEnsinoSuperior]").maskMoney('mask',0.01);

But in the TextBox it puts the value as $ 1.00 instead of $ 0.01

Can anyone help?

    
asked by anonymous 15.06.2018 / 20:17

1 answer

1

Try to change method .val() by method .maskMoney('mask', 0.01);

Example:

$("[id*=tbValorTotalEnsinoSuperior]").maskMoney({ prefix: 'R$ ', thousands: '.', decimal: ',' });
$("[id*=tbValorTotalEnsinoSuperior]").maskMoney('mask', 0.01);

See the result:

$(function() {
  $("#currency").maskMoney({
    prefix: 'R$ ',
    thousands: '.',
    decimal: ','
  }).maskMoney('mask', 0.01);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/jquery-maskmoney/3.0.2/jquery.maskMoney.min.js"></script>
<input type="text" id="currency" />

Update:

Your code works perfectly with .val(); method, see result:

$(function() {

  $("#currency").maskMoney({
    prefix: 'R$ ',
    thousands: '.',
    decimal: ','
  });

  $("#currency").val(0.01);

  $("#currency").maskMoney('mask');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/jquery-maskmoney/3.0.2/jquery.maskMoney.min.js"></script>
<input type="text" id="currency" />
    
15.06.2018 / 20:33