The best currency format in the database

What is the best currency format to use in my database in conjunction with my ASP.NET web application. I'm not sure if float or decimal is better. Please note that I do not need settings for a specific culture.

+3
source share
6 answers

If you are using SQL Server, you have a money type, which converts to a decimal type in .NET.

The decimal digit is a 128-bit base 10 floating-point number, not a binary floating-point number (which is floating / long), which makes it so that in most cases it does not lose accuracy, unlike binary floating-point numbers, which have a loss of accuracy as part of their design.

Here is a good article explaining decimals and floating point logic in general.

+6
source

Do not use float.

decimal value, by specification decimal(17, 4), is probably acceptable. This means "17" places on the left and up to 4 decimal places.

+5
source

, ( ). , .

float, .

+1

. . , , , , , . .

+1

FLOAT , . , , , ..

If you need fractional dollars (i.e. a cent), then choosing DECIMAL is appropriate. Otherwise, you can also stick with INTEGERS so as not to create penny problems.

+1
source
int no=10000;
Console.WriteLine(no.ToString("N2"));
0
source

Source: https://habr.com/ru/post/1716863/


All Articles