Android String to Float Convert getFloatValue(double val, int len)

Here you can find the source of getFloatValue(double val, int len)

Description

get Float Value

Declaration

public static double getFloatValue(double val, int len) 

Method Source Code

//package com.java2s;

public class Main {
    public static double getFloatValue(double val, int len) {
        if (len <= 0) {
            return val;
        }//w  w w .  ja va  2  s  .  co m
        int lastVal = (int) (val * (Math.pow(10, len + 1)))
                - ((int) (val * (Math.pow(10, len)))) * 10;
        if (lastVal < 5) {
            return ((int) (val * (Math.pow(10, len))))
                    / (Math.pow(10, len));
        } else {
            return (((int) (val * (Math.pow(10, len)))) + 1)
                    / (Math.pow(10, len));
        }
    }
}

Related

  1. String2AmountFloat(String str)
  2. isFloat(String str)
  3. isFloat(String str, int precision)
  4. parseFloat(String string, float defValue)
  5. TryParse(String str, float defaultFloat)
  6. parseFloat(String value)