Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

public class Main {

    public static String approximate(int number) {
        if (number == 0) {
            return null;
        }
        if (number < 1000) {
            return String.valueOf(number);
        } else if (number < 10000) {
            float f = number * 1f / 1000;
            return String.valueOf(Math.round(f * 10) / 10.0) + "k";
        } else {
            float f = number * 1f / 10000;
            return String.valueOf(Math.round(f * 10) / 10.0) + "w";
        }
    }
}