Java String format float type by locale

Description

Java String format float type by locale


//package com.demo2s;

import java.util.Locale;

public class Main {
    public static void main(String[] argv) throws Exception {
        int b = 2;
        System.out.println(b2mb(b));
    }//  w  ww.j  a va  2s .c om

    public static float b2mb(int b) {
        String mb = String.format(Locale.getDefault(), "%.2f", (float) b / 1024 / 1024);
        return Float.valueOf(mb);
    }
}



PreviousNext

Related