Android Float Format formatFloatValue(float value)

Here you can find the source of formatFloatValue(float value)

Description

format Float Value

Declaration

static public String formatFloatValue(float value) 

Method Source Code

//package com.java2s;
import android.util.Log;

public class Main {
    public static final int DemicalLength = 3;

    static public String formatFloatValue(float value) {

        if (value <= 0.0f) {
            return "0";
        }// w ww . j  a  v a2  s  .  c  o m

        // TODO: handle the case as: 5.232E-4 ???

        //Float d = new Float(value);
        //String str = d.toString();
        String str = String.valueOf(value);

        Log.d("", " formatFloatValue" + str);
        int index = str.indexOf('.');

        if (index < 0) {
            return str;
        }

        String valueStr;

        String demicalStr = str.substring(index + 1);
        if (demicalStr.length() > DemicalLength) {
            valueStr = new String(str.substring(0, index + DemicalLength));
        } else {
            valueStr = str;
        }

        return valueStr;
    }
}

Related

  1. formatAmount(float f)
  2. formatFloat(float money)
  3. formatAmount(float f)
  4. formatSpeed(float data)
  5. formatSpeed(float data, String format)