1

I have an input for decimal values in HTML:

<input type="number" step="0.01"/>

My model and my variables in C# are declared as decimal as well. But when I, for example, input a number such as 0,15 I get the value of 15 instead of the original 0,15 on my Controller.

I'm posting the data using the form method="post" from HTML

The model is:

public decimal Value { get; set; }

What can I do to receive 0.15 as the value in my controller?

6
  • 2
    how are you posting the data to server, is it an ajax request ? Can you provide the model class? Commented Apr 17, 2019 at 18:26
  • use this link: stackoverflow.com/questions/32908503/… Commented Apr 17, 2019 at 18:27
  • @Vishnu I'm using the method="post" from HTML itself. In my model class I have: public decimal Value { get; set; } Commented Apr 17, 2019 at 18:28
  • 3
    Could it be a culture issue? The comma is ignored as "just a grouping character" instead of decimal Commented Apr 17, 2019 at 18:34
  • Decimal is "." and not ",". Countries like Brazil use comma to decimal and not point. Use point instead.In C#: 150.00M(decimal) and not 150,00M. Commented Apr 17, 2019 at 19:15

2 Answers 2

2

Give the number input with dot "." not comma ","

https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/decimal

For example, C# decimals are given like this, decimal myMoney = 300.5m;

Sign up to request clarification or add additional context in comments.

Comments

0

Problem solved using jQuery maskMoney plugin.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.