c# - Best way to get whole number part of a Decimal number -


What is the best way to return the whole number in decimal (C #)? (It's a great job to work for, which can not fit into an int).

GetIntPart (343564564.4342) & gt; & Gt; 343564564 GetIntPart (-323489.32) & gt; & Gt; -323489 GetIntPart (324) & gt; & Gt; 324

Its purpose is: I want to put a decimal (30,4) field in DB, and want to make sure that I do not want to try to insert a number from that too. Determining the length of the whole number part of a long decimal for the field is a part of this operation.

By people, (int) decimal Maxwell will overflow. You can not get the "int" portion of the decimal because the decimal is very large so that you can put it in the int box. Just checked ... this is too big for a long (Int64).

If you want a bit of decimal value to the LEFT of the dot, then you have to do this:

  Math.Truncate (number)  

And return the value ... a decimal or a double.

Edit: Trinket is definitely the right function!


Comments