C # decimal ToString () method rejected

Can someone explain what happened?

I have a string [i] that has a decimal number in a box and when calling "ToString ()" it gives an integer with 4 trailing zeros.

I also have ((object) 35 m), which also fits in the box, but it does not give zeros.

How could this happen? unless this is a problem with a debugger or c # hard code, I have no ideas.

I am new to stackoverflow, so I cannot attach images. The following URL is a snapshot of the debugger. http://img200.imageshack.us/img200/8749/decimalissuek.jpg

+4
source share
1 answer

Decimal numbers store the number of zeros in them (more precisely, their general precision, which may include trailing zeros):

Console.WriteLine(35m); Console.WriteLine(35.0m); Console.WriteLine(35.00m); Console.WriteLine(35.000m); Console.WriteLine(35.0000m); 

... you will see that zeros are preserved. I assume that your line [i] really has 4 trailing zeros.

+5
source

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


All Articles