Java Integer to String intToStr(int priceInt)

Here you can find the source of intToStr(int priceInt)

Description

int To Str

License

Apache License

Declaration

public static String intToStr(int priceInt) 

Method Source Code

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

public class Main {
    public static String intToStr(int priceInt) {
        boolean isPositivenumber = true;
        if (priceInt <= 0) {
            priceInt = Math.abs(priceInt);
            isPositivenumber = false;//  ww  w.j a va2s. co  m
        }
        if (priceInt == 0) {
            return "0.00";
        }
        String priceStr = priceInt + "";
        String data1 = "";
        String data2 = "";
        int length = priceStr.length();
        if (length >= 3) {
            data1 = priceStr.substring(0, length - 2);
            data2 = priceStr.substring(length - 2, length);
        }
        if (length == 2) {
            data1 = "0";
            data2 = priceStr;
        }
        if (length == 1) {
            data1 = "0";
            data2 = "0" + priceStr;
        }
        priceStr = data1 + "." + data2;
        if (!isPositivenumber) {
            priceStr = "-" + priceStr;
        }
        return priceStr;
    }
}

Related

  1. int2Word(int val)
  2. integerToString(Integer i)
  3. integerToString(Integer number)
  4. integerToString(Integer value)
  5. intToStr(int nValue)
  6. intToStr(int val)
  7. intToStr(int valor, int len)
  8. intToStr(int value)
  9. intToStr(int value, int len)