format Ratio - Android java.lang

Android examples for java.lang:Double

Description

format Ratio

Demo Code

import java.util.Formatter;

public class Main {

  public static final String formatRatio(long num, long den) {
    StringBuilder mFormatBuilder = new StringBuilder(8);
    Formatter mFormatter = new Formatter(mFormatBuilder);
    if (den == 0L) {
      return "---%";
    }//ww w .j  a  va 2s.c  om

    float perc = ((float) num) / ((float) den) * 100;
    mFormatBuilder.setLength(0);
    mFormatter.format("%.1f%%", perc);
    return mFormatBuilder.toString();
  }

}

Related Tutorials