Hi all,
I need to obtain the fractional part of a double. AFAIK C# and .NET has no such function.
Have a few options here:(x is a double)x - (int)x
x - Math.Truncate(x)
Convert to a string and extract the fraction...
Perhaps someone knows other options?
Which should I choose or does it not matter that much?
Thanks in advance for some answers. :)
ddanbe 2,724 Professional Procrastinator Featured Poster
Recommended Answers
Jump to PostI'd use
Truncate
orFloor
because it returns adouble
. If you cast to anint
you might get issues, because adouble
can contain much larger values.As for converting to a string... You're doing math, stick with numbers ;)
All 6 Replies
pritaeas 2,211 ¯\_(ツ)_/¯ Moderator Featured Poster
ddanbe 2,724 Professional Procrastinator Featured Poster
pritaeas 2,211 ¯\_(ツ)_/¯ Moderator Featured Poster
JOSheaIV 119 C# Addict
ddanbe 2,724 Professional Procrastinator Featured Poster
JOSheaIV 119 C# Addict
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.