Here you can find the source of formatSpeed(float speed)
Parameter | Description |
---|---|
speed | a parameter |
public static String formatSpeed(float speed)
//package com.java2s; //License from project: LGPL import java.text.*; public class Main { /**/*from w w w .j a v a 2 s . com*/ * Format a floating point to a String with a 1 digit fraction. * * @param speed * @return String A formated speed string with one digit fraction looking * like 0.1 */ public static String formatSpeed(float speed) { NumberFormat formatter = NumberFormat.getInstance(); if (speed < 1) { formatter.setMaximumFractionDigits(2); formatter.setMinimumFractionDigits(2); } else { formatter.setMaximumFractionDigits(1); formatter.setMinimumFractionDigits(1); } String format = formatter.format(speed); return format; } }