Here you can find the source of floatToString(float value, int precision)
Parameter | Description |
---|---|
value | value |
precision | precision |
public static String floatToString(float value, int precision)
//package com.java2s; /*// w w w.j a v a2 s . com * Java * * Copyright 2016 IS2T. All rights reserved. * Use of this source code is subject to license terms. */ public class Main { /** * Converts a float to a string. * * @param value * value * @param precision * precision * @return a string */ public static String floatToString(float value, int precision) { String str = String.valueOf(value); int dot = str.indexOf('.'); if (precision > 0) { precision++; } if (dot > 0 && str.length() > dot + precision) { str = str.substring(0, dot + precision); } return str; } }