0

I am sending a value from the form data which has to be received as decimal? with comma (,) punctuation. Since I am using input type="number" step="0.1" the punctuation on the client side is with a dot (.).

How can I format the value before the form data is sent to the model?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Sondre
  • 105
  • 2
  • 11
  • 1
    Decimals don't have "punctuation" they just have a numeric value. The local culture number formatting might have punctuation but you can't force c# to store decimals with "punctuation", you can/should only format the number into a string (with "punctuation") when you're outputting – Caius Jard Aug 17 '19 at 22:59
  • Thank you for clarification. However as long as the 'user' is interacting with the value it is being outputted. I am turning the decimal into a string and replacing "," with "." when outputting. I simply want to revert the punctuation before retrieving it to the model – Sondre Aug 17 '19 at 23:07
  • Parse it using an appropriate culture you mean? Your question should probably be posed as "I have a string representing a decimal number in {insert name of country or region} so like 1.234,56 and I want to parse it to a decimal".. but this will have been asked before so try s search first? – Caius Jard Aug 18 '19 at 08:44
  • @CaiusJard I have realy tried implementing cultureinfo but to no avail. I fixed this problem by creating a ViewModel that carries the information as a string. I then do the punctuation in the controller. As I have search a lot regarding this problem I see it less complicated than many other solutions. I just wish there were a single line of code that could fix the problem – Sondre Aug 18 '19 at 23:06
  • Show the code you've already written? – Caius Jard Aug 18 '19 at 23:32
  • @CaiusJard I have the code here: https://stackoverflow.com/questions/57536043/mvc-how-to-fix-null-value-from-httppost-when-formatting-punctuationdecimal-n – Sondre Aug 19 '19 at 01:06

0 Answers0