c# - Determine if a decimal can be stored as int32 -
i doing custom serializing, , in order save space, want serialize decimals int, if possible value wise. performance concern, since dealing high volume of data. current method use is:
if ((value > int32.minvalue) && (value < int32.maxvalue) && ((valueasint = decimal.toint32(value)) == value)) { return true; }
can improved?
do have negative values? i'm guessing yes since have minvalue check, otherwise can skip it. use unsigned int allow convert more of double values ints.
edit: also, if have more positive numbers, can swap first 2 conditions. way first 1 fail, decreasing total number of comparisons.
Comments
Post a Comment