|
-
Oct 6th, 2005, 02:33 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] retrieving decimal in floating variable
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
-
Oct 6th, 2005, 02:54 AM
#2
Re: retrieving decimal in floating variable
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:
Code:
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.
- ØØ -
-
Oct 6th, 2005, 04:24 AM
#3
Re: [RESOLVED] retrieving decimal in floating variable
That gives you 0.1199999.
This is equally ugly but gives you 0.12.
Code:
float value = 15.12f;
decimal decimalPart = (decimal) value - (decimal) Math.Floor(value);
-
Oct 6th, 2005, 05:16 AM
#4
Re: [RESOLVED] retrieving decimal in floating variable
Math.IEEERemainder(someValue, 1)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|