Java Locale Format formatFloat(Float f, int style)

Here you can find the source of formatFloat(Float f, int style)

Description

format Float

License

Apache License

Declaration

public static String formatFloat(Float f, int style) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.text.NumberFormat;
import java.util.Locale;

public class Main {
    public static final int FORMAT_INTEGER = 2;
    public static final int FORMAT_PERCENT = 3;

    public static String formatFloat(Float f, int style) {
        String num = new String("0");

        if (f != null)
            num = new String(f.toString());
        else//from  w ww  .ja v a 2 s.  c o m
            return "";

        NumberFormat nf = null;
        switch (style) {
        case FORMAT_INTEGER: {
            nf = NumberFormat.getIntegerInstance(Locale.US);
            num = nf.format(Double.parseDouble(f.toString()));
            break;
        }
        case FORMAT_PERCENT: {
            nf = NumberFormat.getPercentInstance(Locale.US);
            num = nf.format(Double.parseDouble(f.toString()));
            break;
        }
        default: {
            nf = NumberFormat.getCurrencyInstance(Locale.US);
            num = nf.format(Double.parseDouble(f.toString()));
        }
        }

        return num;
    }
}

Related

  1. formatDuration(long nanoTime)
  2. formatedDate(Date date)
  3. formatElapsedTime(double runTime)
  4. formatEn(T date, String pattern)
  5. formatFloat(float f, int numDecPlaces, boolean forceFractions)
  6. formatFloat(float val)
  7. formatFraction2(final Number value)
  8. formatInCurrentDefaultLocale(double d)
  9. formatingDecimalNumber(Object obj, Locale locale, int maxIntPart, int maxFloatPart)