Java Long Number Create toLong(String s)

Here you can find the source of toLong(String s)

Description

to Long

License

Apache License

Declaration

public static Long toLong(String s) 

Method Source Code

//package com.java2s;
/*//from   w w  w  .ja  va 2s.  c o  m
 * Copyright 2016 Michael Gnatz.
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

public class Main {
    public static Long toLong(String s) {
        if (s == null)
            return null;

        if ("N/A".equals(s))
            return null;

        int dotPos;
        if ((dotPos = s.indexOf('.')) != -1) {
            s = s.substring(0, dotPos + 3);
        }
        try {
            return Long.valueOf(s.replace(".", ""));
        } catch (NumberFormatException e) {
            return null;
        }
    }
}

Related

  1. toLong(String input, int radix, long defaultValue)
  2. toLong(String numeric)
  3. toLong(String param)
  4. toLong(String parameter)
  5. toLong(String s)
  6. toLong(String s)
  7. toLong(String s)
  8. toLong(String s)
  9. toLong(String s)