The byteValue method is used to transform this Float object to primitive type byte. This is basically the core functionality of this method. As we all know a float data type can have decimal digits, what will happen to that. For example if we have the following expression:
Float value = new Float(12.75f);
. What will happen is that the decimal digit will get truncated if we use the byteValue method. What we mean we say the decimal digit will get truncated is that the value returned will be be
As we have discussed on the earlier section of this document is that the range of Float is far greater than the byte primitive type. The byte primitive only has range of 127. So what will happen if we breached that range say for example
Float value = new Float(128f);? For better understanding the minimum value of byte is -128 and max value of 127. If we try to convert greater than 127, the value that will be given is with the formula – + . And if the result is still greater than 128, keep doing – + until the result is within range of byte. So let’say we have a value 128, using the formula i have indicated the result would be -128. So this is the behavior of byteValue() method. As for my own view, I am not sure why we have the need to have this method. I could not see any practical usage yet or maybe I have yet to encounter one.