What is the best way to return the whole number part of a decimal (in c#)? (This has to work for very large numbers that may not fit into an int).
GetIntPart(343564564.4342) >> 343564564
GetIntPart(-323489.32) >> -323489
GetIntPart(324) >> 324
The purpose of this is: I am inserting into a decimal (30,4) field in the db, and want to ensure that I do not try to insert a number than is too long for the field. Determining the length of the whole number part of the decimal is part of this operation.
Depends on what you're doing.
For instance:
or
The default is always the former, which can be a surprise but makes very good sense.
Your explicit cast will do:
From the way you've worded the question it sounds like this isn't what you want - you want to floor it every time.
I would do:
Also check the size of your
decimal
- they can be quite big, so you may need to use along
.