Here you can find the source of bitsRequiredForFraction(String floatnumber)
public static int bitsRequiredForFraction(String floatnumber)
//package com.java2s; //License from project: LGPL public class Main { /**//from w w w .j a v a 2 s . c om * Determines in a Float String how much bits a necessary to represent the * given Fraction with less error than the string. * It is not checked if the float, is a valid float representation. * */ public static int bitsRequiredForFraction(String floatnumber) { if (floatnumber.contains("eE")) { System.out.println("e float represenation not yet supported!"); } int pos = floatnumber.indexOf("."); /* log_2 (10) = 2.30... That means that many bits are enough per decimal digit */ return (int) Math.ceil((floatnumber.length() - pos - 1) * 2.31); } }