Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.math.BigDecimal;

public class Main {

    public static String formatNumber(int number) {
        double kilo = ((double) number) / 1000;
        if (kilo > 1) {
            BigDecimal result = new BigDecimal(Double.toString(kilo));
            return result.setScale(1, BigDecimal.ROUND_HALF_UP).toPlainString() + "k";
        } else {
            return number + "";
        }
    }
}