public final class NumberParser extends Object
Integer.parseInt(String)
, Double.parseDouble(String)
,
etc., in that it respects the current Locale
, allowing to parse
numbers in various formats worldwide.Modifier and Type | Method and Description |
---|---|
static double |
parseDouble(String number)
Parses a
double from the given string, respecting the default
Locale . |
static int |
parseInteger(String number)
Parses an
int from the given string, respecting the default
Locale . |
static Number |
parseNumber(String number)
|
static Number |
parseNumber(String number,
NumberFormat format)
Parses a
Number from the given string, using the given
NumberFormat . |
public static Number parseNumber(String number, NumberFormat format)
Number
from the given string, using the given
NumberFormat
.NumberFormatException
- if the number cannot be parsedpublic static Number parseNumber(String number)
Number
from the given string, respecting the default
Locale
.
Strings representing integers or fractions with a decimal point, optionally signed, are parsed with the US locale. Other strings are first parsed with the default locale and if that fails, parsing is re-attempted using the en-US locale as well before giving up.
NumberFormatException
- if the number cannot be parsedpublic static int parseInteger(String number)
int
from the given string, respecting the default
Locale
. If a decimal number is given as input, the result is
rounded to the nearest integer; see
NumberFormat.getIntegerInstance()
for details.
If parsing with the default locale fails, parsing is reattempted using the en-US locale as well before giving up.
NumberFormatException
- if the number cannot be parsedpublic static double parseDouble(String number)
double
from the given string, respecting the default
Locale
.NumberFormatException
- if the number cannot be parsedCopyright © 2015–2021 Fiji. All rights reserved.