Format decimal number in #0.0 format - Android java.lang

Android examples for java.lang:Double

Description

Format decimal number in #0.0 format

Demo Code

import java.text.DecimalFormat;

public class Main {

  public static String toOneDecimal(String value) {
    Double d = 0d;//www  .  ja  v  a2 s .com
    try {
      d = Double.parseDouble(value);
    } catch (Exception e) {
    }

    DecimalFormat format = new DecimalFormat("#0.0");
    String buf = format.format(d).toString();
    return buf;
  }

}

Related Tutorials