extract fraction values from decimal

S

sony.m.2007

Hi,
I have a decimal value and i need to take the digits after decimal
places(fraction part only).
Is there any simple functions available other than using string
functions(searching for '.' and take the string after that)
decimal decimalValue=12.745
I need to take .745 as another decimal value only from the
decimalValue

Thanks,
Sony
 
J

Jon Skeet [C# MVP]

I have a decimal value and i need to take the digits after decimal
places(fraction part only).
Is there any simple functions available other than using string
functions(searching for '.' and take the string after that)
decimal decimalValue=12.745
I need to take .745 as another decimal value only from the
decimalValue

decimal fraction = decimalValue-Math.Truncate(decimalValue);

Not tested for negative numbers though - you'd want to check exactly
what behaviour you'd want there.
 
N

Nicholas Paldino [.NET/C# MVP]

Sony,

You can always call the Truncate method to get the integral part of the
decimal, and subtract it from the original:

decimal decimalValue = 12.745;
decimal fractionalValue = decimalValue - Decimal.Truncate(decimalValue);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top