Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

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

public class Main {
    /**
     * This used when a double ends in 0 (IE 100.0) and you want 2 decimal places instead (IE 100.00)
     * @param value The double to convert
     * @param addDollarSign boolean, if null passed, nothing, if true passed, will add
     *                      a $ to the begining
     * @return A String, formatted correctly. Will look like this: 104.44 or $99.40
     */
    public static String convertDoubleToStringAddZeroNoRemove(double value, Boolean addDollarSign) {
        String str = Double.toString(value);
        String ending = str.substring((str.length() - 2), (str.length() - 1));
        if (ending.equalsIgnoreCase(".")) {
            str = str + "0";
        }
        if (addDollarSign != null) {
            if (addDollarSign) {
                str = "$" + str;
            }
        }
        return str;
    }
}