Split decimal variable into integral and fraction parts

c#, decimal, fractions, integral

Solution

       decimal fraction = (decimal)2.78;
        int iPart = (int)fraction;
        decimal dPart = fraction % 1.0m;

Problem

I am trying to extract the integral and fractional parts from a decimal value (both parts should be integers): ``` decimal decimalValue = 12.34m; int integral = (int) decimal.Truncate(decimalValue); int fraction = (int) ((decimalValue - decimal.Truncate(decimalValue)) * 100); ``` (for my purpose, decimal variables will contain up to 2 decimal places) Are there any better ways to achieve this?

Original source

Related problems