Java Integer Create toInt(final String value)

Here you can find the source of toInt(final String value)

Description

To int.

License

Apache License

Parameter

Parameter Description
value the value

Return

the int

Declaration

public static int toInt(final String value) 

Method Source Code

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

public class Main {
    /**// ww  w. jav a  2  s  . c om
     * To int.
     *
     * @param value the value
     * @return the int
     */
    public static int toInt(final String value) {
        return (int) toLong(value);
    }

    /**
     * To long.
     *
     * @param value the value
     * @return the long
     */
    public static long toLong(final String value) {
        if (value == null) {
            return 0L;
        }

        String szTemp = "";

        for (int i = 0; i < value.length(); i++)
            if (value.charAt(i) != ',') {
                szTemp = szTemp + value.charAt(i);
            }

        try {
            final double dd = Double.parseDouble(szTemp);
            final long l1 = (long) dd;

            return l1;
        } catch (final NumberFormatException e) {
            final long l = 0L;

            return l;
        }
    }
}

Related

  1. toInt(final String str, final int alt)
  2. toInt(final String str, int defaultValue)
  3. toInt(final String string)
  4. toInt(final String strPriority)
  5. toInt(final String text, final int defaultValue)
  6. toInt(float value)
  7. toInt(int byteSignificance, byte b)
  8. toInt(int[] rgb)
  9. toInt(Integer i)