In c #
double tmp = 3.0 * 0.05;
tmp = 0.15000000000000002
It is connected with money. The value is indeed $ 0.15, but the system wants to round it to $ 0.16. 0.151 should probably be rounded to 0.16, but not 0.15000000000000002
How can I get the correct numbers (e.g. 0.15 or 0.16 if the decimal is large enough).
Use a fixed point variable type or a basic decimal floating point type such as Decimal. Floating-point numbers are always somewhat inaccurate, and binary floating-point representations add another level of inaccuracy when converting to / from base 2.
decimal, . , , .
decimal
, "" , , , . "" (, ) , , float/double ( ) ( ) .
float
double
http://martinfowler.com/eaaCatalog/money.html
, .
Google :
http://books.google.com/books?id=FyWZt5DdvFkC&pg=PT520&lpg=PT520&dq=money+martin+fowler&source=web&ots=eEys-C_vdA&sig=jckdxgMLSRJtGDYZtcbYST1ak8M&hl=en&sa=X&oi=book_result&resnum=6&ct=result
''
A decimal , , .
. , decimal , float.
, , Int32 . - , - . 16- 16 . 1.5 16:16 0x00018000. .
Int32
0x00018000
/sub/mul/div, , mul/div, .
What are you facing - the rounding issue that I mentioned earlier in another post
Is it possible to use "System.Currency" in .NET?
And refer to it also rounding
Source: https://habr.com/ru/post/1697995/More articles:What is monitored and how should it be done? - .netHow can I unzip the newest file in a directory in a .bat file? - build-processFilter "list" divs with javascript - jqueryhttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1697993/utm-and-mgrs-to-latitudelongitude-conversion-source-code&usg=ALkJrhi5WC3kVhdqsCETHxZz_2Gsmoc6-gHow do I specify a validation requirement for users of my class? - .netHow to connect to Oracle database as SYS using ADO connection string? - oracleBad database design. Am I too big a table? - performanceWhat content encoding does the default Perl CGI script use? - perlFocusing on the control when switching tabs - c #How to check a property of a custom object in a data binding script (i.e. a BindingList)? - .netAll Articles