Working with Currency (decimal)

5

I'm working on a project where I had to use decimal for Currency field.

As the American standard and different from the Brazilian soon had some difficulties.

I found some examples of how to deal with it, but I did not get much success. Does anyone have an example or solution to this problem?

    
asked by anonymous 08.11.2014 / 03:18

1 answer

4

In Model , use this:

    [Required]
    [DataType(DataType.Currency)]
    [Display(Name = "Price", ResourceType = typeof(Resources.Language))]
    public Decimal Price { get; set; }

In Views , use the NuGet JQuery Masked Input package , then it is I need to add a @section scripts to your View:

@section scripts {
    <script type="text/javascript">
        $(function() {
            $('#Price').maskMoney({ prefix: 'R$ ', allowNegative: false, thousands: '.', decimal: ',', affixesStay: false });
        });
    </script>
}

Incidentally, it is also good to inform Web.config about the crop used. It's not exactly needed for this case, but it can serve the rest of the system well.

<configuration>
  <system.web>
    ...
    <globalization uiCulture="pt-BR" culture="pt-BR" enableClientBasedCulture="true" />
    ...
  </system.web>
</configuration>
    
08.11.2014 / 03:47