VBForums >
.NET >
C# > [RESOLVED] retrieving decimal in floating variable
Click to See Complete Forum and Search --> : [RESOLVED] retrieving decimal in floating variable
popskie
Oct 6th, 2005, 02:33 AM
hi,
How to get the decimal point of the float or doubld variable.
ex.
100.23 = .23 or 23
.12 = .12 or 12
thanks ,
Popskie
NoteMe
Oct 6th, 2005, 02:54 AM
There might be a cleaner way, but this should at least get you the result. Just be aware, that you are boud to get small rounding errors here:
float myFloat = 15.12f;
int myInt = (int)myFloat;
float myAnswer = myFloat - (float)myInt;
An other way could be to cast it to string, and then find the . sign and then use SubString.
- ии -
penagate
Oct 6th, 2005, 04:24 AM
That gives you 0.1199999.
This is equally ugly but gives you 0.12.
float value = 15.12f;
decimal decimalPart = (decimal) value - (decimal) Math.Floor(value);
jmcilhinney
Oct 6th, 2005, 05:16 AM
Math.IEEERemainder(someValue, 1)
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.