fab etore
,
Greenhorn
i would like to know how can i get the decimal part of a float. I think there must be a method for, by i can't find it.
please help me ;-)
Ron Newman
,
Ranch Hand
float f;
....
float frac = f - (int)f;
fab etore
,
Greenhorn
thanks
Ilja Preuss
,
author
staff
Originally posted by Ron Newman:
float f;
....
float frac = f - (int)f;
That doesn't work well for f > Integer.MAX_VALUE.
Instead you should probably use
float frag = f - Math.ceil(f);
Ron Newman
,
Ranch Hand
But that works properly only for negative numbers...
[ October 14, 2002: Message edited by: Ron Newman ]
Ilja Preuss
,
author
staff
Of course I meant *floor*, not ceil... :roll:
Dirk Schreckmann
,
Sheriff
staff
Or float % 1.
Ilja Preuss
,
author
staff
Originally posted by Dirk Schreckmann:
Or float % 1.
Wow, I didn't know that "%" was defined for floats in Java...
That's certainly the most appropriate solution.
The two armies met. But instead of battle, they decided to eat some pie and contemplate this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com