M
M
masterOk2013-06-13 10:09:13
ASP.NET
masterOk, 2013-06-13 10:09:13

Asp.net mvc data type for money?

public virtual decimal ProductPrice { get; set; }
It turns out that in the database it is saved with a comma, but on the form it asks to enter with a dot, which is why the value is not saved.
How to properly organize work with "Money" What type of data should be and what attributes?

Answer the question

In order to leave comments, you need to log in

5 answer(s)
M
Mikhail Gubanov, 2013-11-14
@lsreg

Can store int in cents/kopecks

O
Oleg Soldatov, 2014-10-22
@Soldata

A year and a half has passed! But I want to give an answer)) When I encountered this trouble, the solution was found to be ideal - I added the methods_ru.js script to the validator on the form. I have been using for many years. Here is where I found it.

L
lavel, 2013-06-13
@lavel

If the database server and IIS are on different servers, then you need to check that the default cultures match, in Russian culture the fractional separator is a comma, in en-US a comma separates the discharge, and the fractional part is separated by a dot. It may be necessary to force the culture to be used in the MVC application.

D
David_KoKos, 2013-11-28
@David_KoKos

use decimal, what culture is there on the database server - it doesn't matter, the main thing for you in your application is to get the correct decimal from the form and that's it, and then just put it in the database, the main thing is that the types match.

K
kakutuzov, 2014-05-13
@kakutuzov

look and read about the IModelBinder interface
in it, parse and pull out the value. At one time, I wrote once and no longer get tired of how the user wrote with a dot or a comma.
PS oh. I was late with the answer)) a year has passed.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question