Package org.apache.poi.ss.format

Examples of org.apache.poi.ss.format.SimpleFraction


            }
            sb.append(Integer.toString((int)wholePart));
            return sb.toString();
        }
       
        SimpleFraction fract = null;
        try{
            //this should be the case because of the constructor
            if (exactDenom > 0){
                fract = SimpleFraction.buildFractionExactDenominator(decPart, exactDenom);
            } else {
                fract = SimpleFraction.buildFractionMaxDenominator((double)decPart, maxDenom);
            }
        } catch (RuntimeException e){
            e.printStackTrace();
            return Double.toString(doubleValue);
        }

        StringBuilder sb = new StringBuilder();
       
        //now format the results
        if (isNeg){
            sb.append("-");
        }
       
        //if whole part has to go into the numerator
        if ("".equals(wholePartFormatString)){
            int trueNum = (fract.getDenominator()*(int)wholePart)+fract.getNumerator();
            sb.append(trueNum).append("/").append(fract.getDenominator());
            return sb.toString();
        }
       
       
        //short circuit if fraction is 0 or 1
        if (fract.getNumerator() == 0){
            sb.append(Integer.toString((int)wholePart));
            return sb.toString();
        } else if (fract.getNumerator() == fract.getDenominator()){
            sb.append(Integer.toString((int)wholePart+1));
            return sb.toString();
        }
       //as mentioned above, this ignores the exact space formatting in Excel
        if (wholePart > 0){
            sb.append(Integer.toString((int)wholePart)).append(" ");
        }
        sb.append(fract.getNumerator()).append("/").append(fract.getDenominator());
        return sb.toString();
    }
View Full Code Here

TOP

Related Classes of org.apache.poi.ss.format.SimpleFraction

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.