If you want to do it with the math library, I would try using math.floor() - look it up in the documentation for java.math. That'll get you the int part, and you can easily get the fractional part from there.
Or you could remove the fractional part by casting the float to an int, which has the same effect. In either case, though, you should verify that your solution works for negative numbers before you turn it in.
If you want to do it using your naked wits, then you've got an interesting challenge. One simpleminded approach would be (assuming the number is positive) to subtract 1 until the number goes negative - then you know how many 1s the number had in it (the magnitude of the integer part) and the fractional part is easily recovered. That's a bit brute-force-ish, but maybe you can improve on it. :)
(btw, the terms "mantissa" and "exponent" don't mean quite that - "mantissa" would be 1.88, exponent would be 0 in your case. if the number were 188, then mantissa would be 1.88, exponent would be 2)
jon.kiparsky
Posting Virtuoso
1,849 posts since Jun 2010
Reputation Points: 383
Solved Threads: 187
See? There's always more than one way to do it.
Quick contest: whoever comes up with the most, um, ingenious solution in the next three hours gets two reputation points. :)
(meaning ingenious in the Rube Goldberg sense, of course!)
jon.kiparsky
Posting Virtuoso
1,849 posts since Jun 2010
Reputation Points: 383
Solved Threads: 187
Jon said something v important - either you do not want mantissa/exponent or your example is completely wrong. You need to check the specs for this project before going any further
JamesCherrill
Posting Genius
6,373 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073
If it really is mantissa/exponent then take log to base 2 and floor that to int - that gives the exponent. Divide by 2^exponent to get the manissa.
psJon re your example - shouldn't the exponent be a power of 2 not a power of 10?
JamesCherrill
Posting Genius
6,373 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073
If you're thinking logs, yes, you're right. "Mantissa" is also the term that I've always heard for the "significand" of a floating-point number, which is what I was thinking. Wikipedia says "significand" is the preferred term for that usage, though - there I go learning something new.
jon.kiparsky
Posting Virtuoso
1,849 posts since Jun 2010
Reputation Points: 383
Solved Threads: 187