Java Formatter Usage alterationValueToString(double value)

Here you can find the source of alterationValueToString(double value)

Description

Format percentage.

License

Open Source License

Parameter

Parameter Description
value double

Return

String

Declaration

public static String alterationValueToString(double value) 

Method Source Code

//package com.java2s;
/*/*from   ww  w  . j ava  2s .co  m*/
 * This file is part of cBioPortal.
 *
 * cBioPortal is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.util.Formatter;

public class Main {
    /**
     * Format percentage.
     *
     * <p/>
     * if value == 0 return "--"
     * case value
     * 0: return "--"
     * 0<value<=0.01: return "<1%"
     * 1<value: return "<value>%"
     *
     * @param value double
     *
     * @return String
     */
    public static String alterationValueToString(double value) {

        // in oncoPrint show 0 percent as 0%, not --
        if (0.0 < value && value <= 0.01) {
            return "<1%";
        }

        // if( 1.0 < value ){
        Formatter f = new Formatter();
        f.format("%.0f", value * 100.0);
        return f.out().toString() + "%";
    }
}

Related

  1. append(final CharSequence seq, final Formatter formatter, final int flags, final int width, final int precision)
  2. asFormattedStr(String format, String eol, Object... objects)
  3. assertion(final boolean test, final String fmt, final Object... params)
  4. byte2Mac(final byte[] m)