Here you can find the source of floatToFormattedString(float f)
Parameter | Description |
---|---|
f | float to trim |
public static String floatToFormattedString(float f)
//package com.java2s; //License from project: Open Source License import java.text.DecimalFormat; public class Main { /**/* w ww . java 2 s .c o m*/ * Shortens numbers to a representable state (#*.###) * @param f float to trim * @return trimmed number as a string */ public static String floatToFormattedString(float f) { if (f == (int) f) { return String.valueOf((int) f); } else { return new DecimalFormat("#.##").format(f); } } }