我要二进制小数转换成decimal.Consider二进制数1101.1110。我知道转换的手工方法,我可以把程序的形式,但我不能够小数部分从数字分开。我需要,因为转换的方法中,后点的不同来分离它。
I want to convert a binary fraction into decimal.Consider binary number 1101.1110. I know the manual method of conversion and i can put in the form of program, but i am not able to separate the fractional part from the number. I need to separate it because the method of conversion differs after the point.
而十进制转换为二进制小数部分可以分开是这样的:
while converting decimal to binary the fractional part can be separated this way:
double num=12.23; int fraction=num-(long)num;u能帮助我。
先谢谢了。
推荐答案我假设你想要的类型的结果双击。解析您的字符串不点,再由两对数字后点的数量的权利功率划分。
I'm assuming you want a result of type double. Parse your String without the point, then divide by the right power of two for the number of digits after the point.
int placesAfterPoint = binaryString.length() - binaryString.indexOf(".") - 1; long numerator = Long.parseLong(binaryString.replace(".", ""), 2); double value = ((double) numerator) / ( 1L << placesAfterPoint );更多推荐
二进制小数转换成Java中十进制
发布评论